Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.4k stars 1.98k forks source link

Unable to upload PDF files to the Media Library via URL #78471

Open filipanoscampos opened 1 year ago

filipanoscampos commented 1 year ago

Quick summary

Our Media Libray allows uploading media files from a URL, but it returns an error for PDF files.

Steps to reproduce

  1. Navigate to your Media Library
  2. Use the arrow next to the Add New button to select the option to Add via URL
  3. Insert your PDF URL (example: https://www.africau.edu/images/default/sample.pdf)
  4. Notice the upload fails and returns the error 1 file could not be uploaded because an error occurred while uploading.

What you expected to happen

The PDF file to show in the Media Library.

What actually happened

The upload fails and an error is returned.

@dragstor noticed this response from an XHR request on an Atomic site:

{
    "code": 400,
    "headers": [
        {
            "name": "Content-Type",
            "value": "application\/json"
        }
    ],
    "body": {
        "error": "",
        "message": ""
    }
}

And this one on a Simple site:

{
    "code": 400,
    "headers": [
        {
            "name": "Content-Type",
            "value": "application\/json"
        }
    ],
    "body": {
        "errors": [
            {
                "file": "https:\/\/www.africau.edu\/images\/default\/sample.pdf",
                "error": "invalid_input",
                "message": "Invalid file type."
            }
        ]
    }
}

Impact

Some (< 50%)

Available workarounds?

Yes, easy to implement

Platform (Simple and/or Atomic)

Simple, Atomic

Logs or notes

6416275-zd-woothemes p2EDhh-20Q-p2#comment-8679

github-actions[bot] commented 1 year ago

Support References

This comment is automatically generated. Please do not edit it.

cuemarie commented 1 year ago

📌 SCRUBBING : RESULT - Replicated / Could Not Replicate / Uncertain

📌 FINDINGS/SCREENSHOTS/VIDEO

Simple Site

Uncaught (in promise) InvalidInputError: Invalid file type.
    e https://wordpress.com/calypso/evergreen/87013.c85f0ade48803b5cbeab.min.js:2
    $ https://wordpress.com/calypso/evergreen/71658.51b98915d12bb5e2dd0b.min.js:2

Atomic Site

Uncaught (in promise) BadRequestError: 
    e https://wordpress.com/calypso/evergreen/87013.c85f0ade48803b5cbeab.min.js:2
    $ https://wordpress.com/calypso/evergreen/71658.51b98915d12bb5e2dd0b.min.js:2

📌 ACTIONS

cuemarie commented 1 year ago

From the slack ping above, agreement so far is that this should be possible, so moving forward as a bug report.

📌 ACTIONS

Shub3am commented 1 year ago

I assume this might be the issue?

const allowedFileTypes = mediaType === 'VIDEO' ? allowedVideoExtensions : allowedImageExtensions;

Code

Shub3am commented 1 year ago

Can i work on this issue?

cuemarie commented 1 year ago

Hey @Shub3am ! Thanks for your interest in contributing! This issue won't be assigned to you specifically at this time, but that's not necessary in order for you to participate! Please refer to: