I am using expo’s FileSystem downloadAsync method to download a file from api (aws). The file is being downloaded in the uri but I’d like to preview( preferably) or save it to the phone’s files.
Is there another way that I can preview this file without downloading, if not. What should I add to this solution.
This is the code that I am using for doing this:
const handleFileDownload = (document) => {
myApi.getDocument(token, document)
.then((result) => {
if (result.ok) {
FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'app_docs/', { intermediates: true });
FileSystem.downloadAsync(
result.url,
FileSystem.documentDirectory + 'app_docs/' + document.fileName
).then(({ uri }) => {
console.log('Finished downloading to ', uri);
})
.catch(error => {
console.error('error downloading: ', error)
})
}
})
.catch((err) => {
console.log('Could not communicate with the server!', err.message)
})
}