Skip to content
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

Fix handling of pasted images and prevent thumbnail uploads #18215

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@ export class ImageEdit extends React.Component {
console.warn( 'Attributes has id with no url.' );
}

// Detect any pasted image and start an upload
if ( ! attributes.id && attributes.url && attributes.url.indexOf( 'file:' ) === 0 ) {
requestMediaImport( attributes.url, ( id, url ) => {
if ( url ) {
setAttributes( { id, url } );
}
} );
}

// Make sure we mark any temporary images as failed if they failed while
// the editor wasn't open
if ( attributes.id && attributes.url && ! isURL( attributes.url ) ) {
if ( attributes.url.indexOf( 'file:' ) === 0 ) {
requestMediaImport( attributes.url, ( id, url ) => {
if ( url ) {
setAttributes( { id, url } );
}
} );
}
mediaUploadSync();
}
}
Expand Down
12 changes: 3 additions & 9 deletions packages/block-library/src/media-text/media-container.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,9 @@ class MediaContainer extends Component {
componentDidMount() {
const { mediaId, mediaUrl, onMediaUpdate, mediaType } = this.props;

if ( mediaId && mediaUrl && ! isURL( mediaUrl ) ) {
if ( mediaUrl.indexOf( 'file:' ) === 0 && mediaType === MEDIA_TYPE_IMAGE ) {
// We don't want to call this for video because it is starting a media upload for the cover url
requestMediaImport( mediaUrl, ( id, url ) => {
if ( url ) {
onMediaUpdate( { id, url } );
}
} );
}
// Make sure we mark any temporary images as failed if they failed while
// the editor wasn't open
if ( mediaId && mediaUrl && mediaUrl.indexOf( 'file:' ) === 0 && mediaType === MEDIA_TYPE_IMAGE ) {
mediaUploadSync();
}
}
Expand Down