@@ -31,7 +31,7 @@ import {
3131 applyAutoCacheToMessages ,
3232 applyAutoCacheToSystem ,
3333} from './promptCache' ;
34- import { getFormatFromMimeType } from './media' ;
34+ import { getFormatFromMimeType , getMimeTypeFromFileName } from './media' ;
3535
3636// Default Models
3737
@@ -358,10 +358,16 @@ const createConverseCommandInput = (
358358 // Put images, videos, and documents before the task, instruction, and user query
359359 if ( message . extraData ) {
360360 message . extraData . forEach ( ( extra ) => {
361+ // Prior to v4.2.4, 'extra.source.mediaType' could be empty.
362+ // For resumed conversations from older versions, we fallback to detecting mimeType based on the extension.
363+ const mimeType =
364+ extra . source . mediaType || getMimeTypeFromFileName ( extra . name ) ;
365+ const format = getFormatFromMimeType ( mimeType ) ;
366+
361367 if ( extra . type === 'image' && extra . source . type === 'base64' ) {
362368 contentBlocks . push ( {
363369 image : {
364- format : getFormatFromMimeType ( extra . source . mediaType ) ,
370+ format,
365371 source : {
366372 bytes : Buffer . from ( extra . source . data , 'base64' ) ,
367373 } ,
@@ -370,7 +376,7 @@ const createConverseCommandInput = (
370376 } else if ( extra . type === 'file' && extra . source . type === 'base64' ) {
371377 contentBlocks . push ( {
372378 document : {
373- format : getFormatFromMimeType ( extra . source . mediaType ) ,
379+ format,
374380 name : extra . name
375381 . split ( '.' ) [ 0 ]
376382 . replace ( / [ ^ a - z A - Z 0 - 9 \s \- ( ) [ \] ] / g, 'X' ) , // If the file name contains Japanese, it will cause an error, so convert it
@@ -382,7 +388,7 @@ const createConverseCommandInput = (
382388 } else if ( extra . type === 'video' && extra . source . type === 'base64' ) {
383389 contentBlocks . push ( {
384390 video : {
385- format : getFormatFromMimeType ( extra . source . mediaType ) ,
391+ format,
386392 source : {
387393 bytes : Buffer . from ( extra . source . data , 'base64' ) ,
388394 } ,
@@ -391,7 +397,7 @@ const createConverseCommandInput = (
391397 } else if ( extra . type === 'video' && extra . source . type === 's3' ) {
392398 contentBlocks . push ( {
393399 video : {
394- format : getFormatFromMimeType ( extra . source . mediaType ) ,
400+ format,
395401 source : {
396402 s3Location : {
397403 uri : extra . source . data ,
0 commit comments