-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use proper named File
when uploading external images
#65693
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +40 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, @swissspidy! 🙌
I tested this from the media tab in the editor, and it does work as intended. In the case of stocksnap.io
images, the names could be more meaningful if we were using the image URL (https://cdn.stocksnap.io/img-thumbs/960w/fruit-vegetables_F8B73CPSBK.jpg
) instead of the thumbnail URL (https://cdn.stocksnap.io/img-thumbs/960w/F8B73CPSBK.jpg
), which seems to be the case at the moment. That said, even if we want to improve that, it would probably best be done in a different PR.
@@ -167,8 +168,13 @@ export function MediaPreview( { media, onClick, category } ) { | |||
.fetch( url ) | |||
.then( ( response ) => response.blob() ) | |||
.then( ( blob ) => { | |||
const fileName = getFilename( url ) || 'image.jpg'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for other reviewers: the fallback uses .jpg
regardless of the actual file type, since we rely on the server to choose an appropriate file extension for us. We do need to provide some image-related file extension, however, even if it's wrong, otherwise the server will outright reject the upload.
Do we even have access to the full URL in this component? Maybe from the |
…ress#65693)" This reverts commit 0301198.
What?
When uploading an Openverse image, the image won't have a name because we are just uploading a
Blob
instead of aFile
as expected bymediaUpload()
. The browser will then default to something likeimage.jpg
.This changes that.
Why?
We should use a proper
File
object with an actual image name so that you don't have dozens ofimage-x.jpg
files in the media library.A similar change was recently done in #65122.
How?
Uses
getFilename
to get an image name from a URL, only usingimage.jpg
as a fallback.Testing Instructions
Testing Instructions for Keyboard
N/A
Screenshots or screencast