I use @capawesome/capacitor-file-picker
for pick files on mobile. Yet it does not return blob.
const result = await FilePicker.pickFiles({
types: ['application/pdf'],
multiple: false,
});
const file = result.files[0];
if(file.blob){ **//fails here because file.blob not exist**
const rawFile = new File([file.blob as BlobPart], file.name, {
type: file.mimeType,
});
callback(rawFile, file.name)
}
when I console.log the file:
mimeType: "application/pdf"
modifiedAt: 1696191033806
name: "filename.pdf"
path: "file:///path/to/file/filename.pdf"
size: 1332512
There's no blob :(
Get the blob of the file, when console.log(file) it should be:
blob: `sum-blob`
mimeType: "application/pdf"
modifiedAt: 1696191033806
name: "filename.pdf"
path: "file:///path/to/file/filename.pdf"
size: 1332512
So actually capacitor file picker, when pick file we can use the
readData
option to betrue
. So it would look like this:It will return:
That
data
is abase64
of the file, so we can convert it to blob using this function I found around the internet:So then we can:
It return the base64 as blob :) that
rawFile
already contain the blob!