@leonardofmed wrote:
Context
I have a function that grab some files, add them to a zip file and save in device’s storage. The function uses JSZip, and was working great until I tried to add images to the zip file. JSZip has an option to receive the image file as base64, so I tried with it. To get the images as base64 from the device storage I’m using the function
readAsDataURL
from the Ionic File plugin.
My converter function
async uriToBase64(uri) { console.log('File received to be converted: ', uri); let nameFile = uri.replace(this.file.dataDirectory, ''); console.log("File name to be converted: ", nameFile); await this.file.readAsDataURL(this.file.dataDirectory, nameFile).then((file64) => { let fileWithoutExtension = ('' + file64 + '').replace(/^data:image\/(png|jpg|jpeg);base64,/, ''); console.log("File without extension: ", fileWithoutExtension); return fileWithoutExtension; }) .catch(err => { console.log("Error while transforming image to base64: ", err); }); }
The problem
I’m receiving the “File without extension” log, but I’m also receiving an error that blocks the save of my zip file. The error is the following:Error: Can’t read the data of ‘1566993701809.jpg’. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?
I believe this is a problem with the JSZip plugin, but it should read the images as base64. I tried without the async function also, but the image files inside the zip got size equal 0, so I thought it might be because the function had not read the image yet. Then I got this error.
How my base64 look like
Don’t know if will be useful, but this is part of what returns from my convert function:
/9j/4QEmRXhpZgAASUkqAAgAAAAPAJqCCgABAAAAwgAAABABAgAKAAAAygAAAAABAwABAAAACAQAAJ2CCgABAAAA1AAAAAOkAwABAAAAAAAAAAmSAwABAAAAAAAAAA8BAgAIAAAA3AAAACeICAABAAAA4gQAAAqSBQABAAAA5AAAAAiSAwABAAAAAAAAABIBAwABAAAAAQAAAAeSAwABAAAA/////wEBAwABAAAALAcAADIBAgAUAAAA7AAAAGmHBAABAAAAAAEAAAAAAABDAAAA6AMAAFNNLUU1MDBNAAAWAAAACgAAAFNBTVNVTkcASgEAAGQAAAAyMDE5OjA4OjI4IDA5OjAyOjE5AAIAAQIEAAEAAAAeAQAAAgIEAAEAAAAAAAAAAAAAAP/bAEMAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA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