expo-file-dl
expo-file-dl copied to clipboard
PDFs are not downloaded, but sharing dialog is opened instead
Hi. Thanks for the great library. Tried to download a PDF, but it's not downloaded at all in iOS. The native iOS sharing dialog is opened instead.
I see this is as designed:
// if this is not an image file on iOS
// we use "Sharing" library and quit early (let iOS handle it)
if (ios &&
imageFileExts.every((x) => !downloadedFile.uri.toLocaleLowerCase().endsWith(x))) {
const UTI = "public.item";
const shareResult = await Sharing.shareAsync(downloadedFile.uri, {
UTI,
});
return true;
Is there a particular limitation for PDF files in iOS? iOS can't handle them even when downloaded into Documents or Downloads folder? I'd be willing to give a shot with a PR if you point me in the right direction.
@augustosamame
From looking around, I believe this is a limitation of iOS. You are meant to provide user's with options on what they want to do with a document instead of forcing a download to a folder. Here's an example answer from Stack Overflow:
This is an example of a way to save a document. You can't force it to be downloaded and show up in their Files app. You have to present a UIActivityViewController that shows options on what they can do with that document.
- https://stackoverflow.com/questions/50128462/how-to-save-document-to-files-app-in-swift
What can be done is that you can add the following keys to your info.plist: "UISupportsDocumentBrowser", "UIFileSharingEnabled", "LSSupportsOpeningDocumentsInPlace". and then any files you download through the app to the app's internal storage will be exposed to the user's My Files app. You will still not be able to directly download any files directly to the Downloads / Documents folders in My Files, but you could download a file to, say, MyApp/Documents/ which would be accessible in the My Files app.
Hope that makes sense. This library can't control people's info.plist but we could make it possible to disable the Sharing dialog (if you are on iOS then the Sharing dialog wouldn't open, your file would be downloaded to MyApp/Documents/ in the My Files app, but you would be responsible for setting info.plist to expose the MyApp directory to users). I could add a configuration option to enable this method of downloading files for those who prefer it to the Sharing dialog.