Have you updated your app to v19? You may be stuck with an old version of the Assets code that doesn’t play nicely. Try rm -rf node_modules/ && npm i and let us know if you’re still having the issue.
I should mention that while testing this, the file is downloaded correctly, but I haven’t been able to read the contents. That may likely be a separate issue.
I tried your code then I implemented what I wanted to do!! (read a contents from dropbox)
Maybe, the reason of the error was because the file was not downloaded and it was not able to see from the local.
Hey, I’m trying to do the same thing, but picking a file from Downloads (on Android). in FileSystem.downloadAsync it throws the error unexpected url: content://com.android.providers.downloads.documents/document/237 (FileSystem.java:248). Anyone know what the problem is? I am on 19.0.0 according to the Info page.
I tried making a snack to demonstrate the problem (https://snack.expo.io/HJQRWEKPb), but the DocumentPicker doesn’t pop up there, not sure why.
i used this code : const read = await FileSystem.readAsStringAsync(fileUri)
but when reading the file as string, convert it to base64 and upload it to the server, i only get the file without the content at all. (just an empty content)
anyone can help me with this?
async _selectDocument() {
let result = await DocumentPicker.getDocumentAsync({});
try {
if (result.type === ‘success’) {
const fileUri = ${FileSystem.documentDirectory}${result.name} → get the fileUri
await fetch(fileUri)
.then(response => response.blob()) --> fetch the fileUri to blob
.then(blob => {
var reader = new FileReader();
reader.readAsDataURL(blob); --> The readAsDataURL method is used to read the contents of the specified Blob or File.
reader.onloadend = () => {
var base64 = reader.result;
this.setState({
fileUrl: fileUri,
fileName: result.name,
fileData: base64, --> put the set state on the onloadend method
});
console.log(base64);
};
})
.catch(error => console.error(error))
} else if (result.type === 'cancel') {
alert("Select File Cancelled");
console.log("Select File Cancelled");
}
}
catch (error) {
alert("File Not Found! Please Try Again!");
console.log("File Not Found! Please Try Again!" + error);
}
}
i didn’t use the FileSystem.readAsStringAsync. Because when i’m using this, convert to base64, and after i upload it to the server, the file become empty and the size didn’t match.