-
Notifications
You must be signed in to change notification settings - Fork 805
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
Media Library: Implement upload media from URL #41089
base: trunk
Are you sure you want to change the base?
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! |
85afb83
to
24a4df4
Compare
3acc461
to
3f8e1cb
Compare
3f8e1cb
to
ba93666
Compare
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.
Tested this both on Media -> Library and Site Editor and worked well 👍
buttonText = __( 'Uploading…', 'jetpack-mu-wpcom' ); | ||
} | ||
return ( | ||
<form onSubmit="return false;"> |
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.
Should we change this to:
<form onSubmit="return false;"> | |
<form onSubmit="handleSubmit"> |
with <button type='submit'>
?
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.
Oh you're right... what was I thinking 🤦 thanks!
|
||
import './style.scss'; | ||
|
||
const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isSiteEditor } ) => { |
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.
It seems that
Screen.Capture.on.2025-01-22.at.17-12-33.mp4 |
selection.reset(); | ||
selection.add( [ attachment ] ); | ||
} else { | ||
window.wp.media.frame.content.get().collection.add( attachment ); |
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.
Opening the attachment details modal updates the reference of content
so collection
is no longer accessible. Directly referencing window.wp.media.frame.controller.browserView.collection.add()
seems to do the trick, something to consider.
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.
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.
Thanks all for checking, looks like another session of hours debugging/exploring Core wp
objects is incoming... 😅
|
||
$url = esc_url_raw( wp_unslash( $_POST['url'] ) ); | ||
|
||
$tmp = download_url( $url ); |
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.
nit: it would be better to call it something like $tmp_file
selection.reset(); | ||
selection.add( [ attachment ] ); | ||
} else { | ||
window.wp.media.frame.content.get().collection.add( attachment ); |
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.
It's all based on the design in https://github.com/Automattic/dotcom-forge/issues/10180#issuecomment-2572909885. @jameskoster, thoughts? |
Yep but the design doesn't have the storage usage there. Maybe we can remove it since there is another one below the page title 🤔 |
f6c24d0
to
d37ff21
Compare
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.
I could check the visual updates 👍
window.wp.media.frame.content.get().collection.add( attachment ); | ||
window.wp.media.frame.controller.browserView.collection.add( attachment ); |
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.
(Sorry if you're still working on it)
I got TypeError: Cannot read properties of undefined (reading 'browserView')
and infinite loading on the /wp-admin/upload.php page.
Screen.Recording.2025-01-27.at.15.54.39.mov
(When I reload the page, the new image is added, though...)
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.
Oh, I could upload the image without errors only when I opened the preview modal before uploading it.
Fixes https://github.com/Automattic/dotcom-forge/issues/10180
Proposed changes:
This PR implements the feature where we can upload media files from URL in the Media Library and Site Editor.
The UX is implemented by following the default file upload behavior as similar as possible.
See the following videos:
Media Library
48MySt.mp4
Site Editor
lFwwGW.mp4
Implementation Details
This feature is implemented by showing a simple url input form after the
Plupload
uploader via thepost-plupload-upload-ui
hook. On submitting the form, it calls an AJAX handler, which then call Core'sdownload_url()
and thenmedia_handle_sideload()
. This logic is very similar to that of the original endpoint used by Calypso version of the Media Library.Limitations
Failure Cases
The upload form can handle failure cases, e.g. when the media has unsupported extension. It will show an error notice, similar to when we upload the file via the dropzone:
PwQbJv.mp4
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: