diff --git a/components/missions/file-upload.tsx b/components/missions/file-upload.tsx index aaef13be..bc7e6d0c 100644 --- a/components/missions/file-upload.tsx +++ b/components/missions/file-upload.tsx @@ -104,7 +104,7 @@ export function FileUpload({ return true; }; - const handleFileDrop = (e: React.DragEvent) => { + const handleFileDrop = async (e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsDragging(false); @@ -115,11 +115,21 @@ export function FileUpload({ setFile(droppedFile); // If this is a new mission, call onFileSelect instead of waiting for upload if (isNewMission && onFileSelect) { - onFileSelect({ - data: URL.createObjectURL(droppedFile), - name: droppedFile.name, - type: droppedFile.type - }); + try { + const base64 = await convertFileToBase64(droppedFile); + onFileSelect({ + data: base64, + name: droppedFile.name, + type: droppedFile.type + }); + } catch (error) { + console.error('Error converting file to base64:', error); + toast({ + title: 'Error', + description: 'Failed to process file. Please try again.', + variant: 'destructive', + }); + } } } } @@ -191,11 +201,21 @@ export function FileUpload({ // For new missions, just notify through the callback and don't try to upload if (isNewMission) { if (onFileSelect) { - onFileSelect({ - data: URL.createObjectURL(fileToUpload), - name: fileToUpload.name, - type: fileToUpload.type - }); + try { + const base64 = await convertFileToBase64(fileToUpload); + onFileSelect({ + data: base64, + name: fileToUpload.name, + type: fileToUpload.type + }); + } catch (error) { + console.error('Error converting file to base64:', error); + toast({ + title: 'Error', + description: 'Failed to process file. Please try again.', + variant: 'destructive', + }); + } } toast({ title: 'File selected',