heic2any icon indicating copy to clipboard operation
heic2any copied to clipboard

Argument of type 'Blob | Blob[]' is not assignable to parameter of type 'Blob'.

Open shamoons opened this issue 3 years ago • 1 comments

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

shamoons avatar Sep 12 '22 14:09 shamoons

That's because the heic2any can also handle multiple files. When your sure to only convert one file you could write:

...
const convertedFile = (await heic2any({ blob: imgBlob })) as Blob;
...

At least that's how I did it. 🤷

pcoeper avatar Sep 14 '22 07:09 pcoeper