capacitor-file-selector icon indicating copy to clipboard operation
capacitor-file-selector copied to clipboard

Unable to fetch the selected file

Open peterarends opened this issue 5 years ago • 1 comments

const file = await fetch(selectedFile.paths[index]).then((r) => r.blob());

This is not working for me (in my Vue app using Nuxt). It will always return the index.html (or an empty gif).

When I remove the "_capacitor_file_" bit like so:

let path = paths[index].replace("_capacitor_file_", "");

And grab the file this way:

const file = await fetch(Capacitor.convertFileSrc(path)).then(r => r.blob());

That way it does work. What am I doing wrong? It took some time getting it to work. I hope by posting this, it will help others out.

peterarends avatar Nov 03 '20 19:11 peterarends

Hello @peterarends

You can also create the blob type by this way

const blob = new Blob([data.item(i)], {type: data.item(i).type});

abritopach avatar Nov 08 '20 17:11 abritopach