Reputation: 43569
I'm doing:
const heicReader = new FileReader();
heicReader.onload = async () => {
const heicImageString = heicReader.result;
const { download_url } = await uploadPhotoToGcs({
base64: heicImageString,
type: 'image/png',
});
this.onSubmitImageMessage(download_url);
};
const blobUrl = URL.createObjectURL(imageData);
const blobRes = await fetch(blobUrl);
const imgBlob = await blobRes.blob();
const convertedFile = await heic2any({ blob: imgBlob });
heicReader.readAsDataURL(convertedFile);
return;
And the heicReader.readAsDataURL(convertedFile);
complains about:
const convertedFile: Blob | Blob[]
Argument of type 'Blob | Blob[]' is not assignable to parameter of type 'Blob'.
Type 'Blob[]' is missing the following properties from type 'Blob': size, type, arrayBuffer, stream, text
What am I missing?
Upvotes: 1
Views: 372
Reputation: 26344
Since it can return an array of blobs, you need to check if it is not an array before using it:
const convertedFile = await heic2any({ blob: imgBlob });
if (!Array.isArray(convertedFile)) heicReader.readAsDataURL(convertedFile);
else { /* convertedFile is an array of blobs */ }
but you should also consider the case if it is an array of blobs. Would you then try to read only the first one?
if (!Array.isArray(convertedFile)) heicReader.readAsDataURL(convertedFile);
else heicReader.readAsDataURL(convertedFile[0]));
Upvotes: 2