Skip to content

Commit

Permalink
Use proper named File when uploading external images (#65693)
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Sep 28, 2024
1 parent faa6968 commit 5ac6838
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { moreVertical, external } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
import { isBlobURL } from '@wordpress/blob';
import { getFilename } from '@wordpress/url';

/**
* Internal dependencies
Expand Down Expand Up @@ -167,8 +168,13 @@ export function MediaPreview( { media, onClick, category } ) {
.fetch( url )
.then( ( response ) => response.blob() )
.then( ( blob ) => {
const fileName = getFilename( url ) || 'image.jpg';
const file = new File( [ blob ], fileName, {
type: blob.type,
} );

settings.mediaUpload( {
filesList: [ blob ],
filesList: [ file ],
additionalData: { caption },
onFileChange( [ img ] ) {
if ( isBlobURL( img.url ) ) {
Expand Down

0 comments on commit 5ac6838

Please sign in to comment.