Skip to content

Commit

Permalink
Fix handling of pasted images and prevent thumbnail uploads (#18215)
Browse files Browse the repository at this point in the history
* Fix handling of pasted images and prevent thumbnail uploads

* Fix lint errors

* Remove check for image for sync.
  • Loading branch information
koke authored and SergioEstevao committed Nov 1, 2019
1 parent d56979d commit 13ba7dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
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
17 changes: 5 additions & 12 deletions packages/block-library/src/media-text/media-container.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { View, ImageBackground, Text, TouchableWithoutFeedback } from 'react-native';
import {
requestMediaImport,
mediaUploadSync,
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
Expand Down Expand Up @@ -62,17 +61,11 @@ 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 } );
}
} );
}
const { mediaId, mediaUrl } = this.props;

// 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 ) {
mediaUploadSync();
}
}
Expand Down

0 comments on commit 13ba7dc

Please sign in to comment.