Skip to content
Draft
Prev Previous commit
Next Next commit
Implement server-side HEIC conversion flow with converted file fetching
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
  • Loading branch information
Copilot and swissspidy committed Nov 12, 2025
commit b46a6a3c1ca04b8519dbb4d8aa6956bd9f63c0fa
48 changes: 48 additions & 0 deletions packages/upload-media/src/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ export function prepareItem( id: QueueItemId ) {
let uploadOriginalImage = false;

const supportsHeicOnServer = select.getSettings().supportsHeic;
const serverWillConvertHeic = isHeif && convertUnsafe && supportsHeicOnServer;

if ( convertUnsafe ) {
if ( isHeif ) {
Expand All @@ -900,6 +901,27 @@ export function prepareItem( id: QueueItemId ) {
}
}

// For HEIC files that will be converted server-side,
// upload first, then do all processing on the converted file.
if ( serverWillConvertHeic ) {
operations.push( OperationType.Upload );

operations.push( OperationType.GenerateMetadata );

const useAi: boolean = registry
.select( preferencesStore )
.get( PREFERENCES_NAME, 'useAi' );

if ( useAi ) {
operations.push( OperationType.GenerateCaptions );
}

operations.push( OperationType.ThumbnailGeneration );

// Done with server-side HEIC conversion flow.
break;
}

const imageSizeThreshold: number = registry
.select( preferencesStore )
.get( PREFERENCES_NAME, 'bigImageSizeThreshold' );
Expand Down Expand Up @@ -1946,6 +1968,32 @@ export function uploadItem( id: QueueItemId ) {
}
}

// If this was a HEIC file uploaded to a server that supports HEIC conversion,
// we need to fetch the converted JPEG file back to use for thumbnail generation.
const isHeicFile = item.sourceFile.type === 'image/heic' || item.sourceFile.type === 'image/heif';
const supportsHeicOnServer = select.getSettings().supportsHeic;

if ( isHeicFile && supportsHeicOnServer && attachment.url ) {
// Add a FetchRemoteFile operation to get the converted JPEG.
// This will update item.file to the converted file so thumbnails can be generated.
const fileName = attachment.mexp_filename || item.sourceFile.name;

dispatch< AddOperationsAction >( {
type: Type.AddOperations,
id,
operations: [
[
OperationType.FetchRemoteFile,
{
url: attachment.url,
fileName,
skipAttachment: true,
},
],
],
} );
}

dispatch.finishOperation( id, {
attachment,
timings,
Expand Down