I am using Expo file system and expo sharing to download PDF files from my express server. I am encountering a weird issue where on Android it works as expected, but on IOS, when i choose the Save to files option, the file does not save. The strange part is if I select another option from the share menu, such as send via text message, the file is sent properly. Any ideas?
const save = async (uri, filename, mimetype) => {
if (Platform.OS === 'android') {
const permissions = await FileSystem.StorageAccessFramework.requestDirectoryPermissionsAsync()
if (permissions.granted) {
const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 })
await FileSystem.StorageAccessFramework.createFileAsync(permissions.directoryUri, filename, mimetype)
.then(async (uri) => {
await FileSystem.writeAsStringAsync(uri, base64, { encoding: FileSystem.EncodingType.Base64 })
})
.catch((e) => console.log(e))
} else {
shareAsync(uri)
}
} else {
await shareAsync(uri, { mimeType: mimetype, UTI: mimetype })
}
}
const downloadFile = async () => {
try {
setFileLoading(true)
const config: any = { headers: { responseType: 'application/pdf' } }
const fileName = `myfile.pdf`
const result = await FileSystem.downloadAsync(
'apiPath',
FileSystem.documentDirectory + `/${fileName}/`
)
save(result.uri, fileName, 'application/pdf')
} catch (error) {
console.log(error)
} finally {
setFileLoading(null)
}
}
I dont know what else to try, but as I said before, downloading the file on android works as expected, and IOS allows me to interact with the files in different ways other than downloading.