uri returned from writeFile is urlencoded
TechplexEngineer opened this issue · comments
Thanks for the great plugin, this really saved my bacon!
One thing I noticed is if the filename/path used with writeFile contains characters like :
they are escaped and saveToDownloads
generates a very nondescript error.
Sample code that is broken:
const filename = `${colName}-${new Date().toISOString()}.json`;
let res = await Filesystem.writeFile({
path: filename,
data: data,
directory: Directory.Data,
encoding: Encoding.UTF8
});
console.log("create file", res);
let res2 = await Mediastore.saveToDownloads({
filename: filename,
path: res.uri
});
The fix is fairly simple by decoding the URI before passing it to saveToDownloads the error goes away
Working Code:
const filename = `${colName}-${new Date().toISOString()}.json`;
let res = await Filesystem.writeFile({
path: filename,
data: data,
directory: Directory.Data,
encoding: Encoding.UTF8
});
console.log("create file", res);
let res2 = await Mediastore.saveToDownloads({
filename: filename,
path: decodeURIComponent(res.uri)
});