flutter_downloader icon indicating copy to clipboard operation
flutter_downloader copied to clipboard

Download is not working in IOS Simulator

Open gopi1315 opened this issue 3 years ago • 18 comments

We have implemented flutter_downloader library for downloading the either jpg/pdf files. Its working fine in Android Devices. But when we are trying to download in IOS Simulator we'r getting the error : URLSession:task:didCompleteWithError: in xCode.

For IOS , followed the complete guidelines which has mentioned in the library documentation.

IOS Version : 14.4

String savedDirPath = Platform.isAndroid ? await ExtStorage.getExternalStoragePublicDirectory( ExtStorage.DIRECTORY_DOWNLOADS) : (await getApplicationDocumentsDirectory()).path;

await FlutterDownloader.enqueue( url: baseURL + downloadUrl, savedDir: savedDirPath, showNotification: true, openFileFromNotification: true, );

gopi1315 avatar May 03 '21 11:05 gopi1315

Im facing the same issue.. Couldn't find any soultion.

xirainfotech avatar May 03 '21 13:05 xirainfotech

facing same issue have asked about it here https://stackoverflow.com/questions/67336422/flutter-downloader-not-working-with-dynamic-url https://github.com/fluttercommunity/flutter_downloader/issues/463

parthgandhi85 avatar May 04 '21 05:05 parthgandhi85

Little update on this.. File is being downloaded but it is not displayed in device.. ive used then method after downloading file. Something like this> await FlutterDownloader.enqueue( url: "someUrlFromApi", savedDir: externalDir.path, // fileName: fileName, showNotification: true, openFileFromNotification: true, ).then( (value) => Snacks.darkSnack( title: 'Downloaded', subtitle: 'Click here to open', onTap: (_) { FlutterDownloader.open(taskId: value); }, ), );

And it opens that files but. doesn't give any preview of it

xirainfotech avatar May 04 '21 05:05 xirainfotech

Little update on this.. File is being downloaded but it is not displayed in device.. ive used then method after downloading file. Something like this> await FlutterDownloader.enqueue( url: "someUrlFromApi", savedDir: externalDir.path, // fileName: fileName, showNotification: true, openFileFromNotification: true, ).then( (value) => Snacks.darkSnack( title: 'Downloaded', subtitle: 'Click here to open', onTap: (_) { FlutterDownloader.open(taskId: value); }, ), );

And it opens that files but. doesn't give any preview of it

do you use dynamic download links?

parthgandhi85 avatar May 04 '21 05:05 parthgandhi85

I dont know what exactly you mean by dynamic download links

xirainfotech avatar May 04 '21 06:05 xirainfotech

i mean to say that i get my download url end point from another api and i append that end point in base url . when i pass static url it downloads file correctly and i can view and open it but as soon as i pass dynamic url it doesnt download.

parthgandhi85 avatar May 04 '21 06:05 parthgandhi85

Oh, Yes my download url is also coming from and endpoint.. How are you able to see file? Can you please share code snippets

xirainfotech avatar May 04 '21 07:05 xirainfotech

i already shared code in the question i asked. i have attached the link in previous comments

parthgandhi85 avatar May 04 '21 07:05 parthgandhi85

Hey i think there must be some issue in your link. Your code where BASE_URL="http://server.com" // it should be like. http://server.com/endpoint/file.pdf DOWNLOAD_PDF="endpoint/" fileName="file.pdf"

await FlutterDownloader.enqueue(
       url: BASE_URL+DOWNLOAD_PDF+fileName, // HERE I GUESS IT IS NOT GETTING PROPER URL
       savedDir: value,
       showNotification: false, 
       openFileFromNotification: false)

xirainfotech avatar May 04 '21 08:05 xirainfotech

In my case, when i checked the Application folder of IOS Simulator through Finder the file is got downloaded. But in Notification its not displaying like how it displays in Android.I didn't checked with the real device.

gopi1315 avatar May 04 '21 11:05 gopi1315

In my case, when i checked the Application folder of IOS Simulator through Finder the file is got downloaded. But in Notification its not displaying like how it displays in Android.I didn't checked with the real device.

Yes no notifications for me as well, Checked on real device too. Also ive enabled background mode too as mentioned in docs

xirainfotech avatar May 05 '21 04:05 xirainfotech

in iOS 15 I can't see downloaded file

rkoshti avatar Jan 13 '22 11:01 rkoshti

Did anyone find the solution ? Everything works fine in android. But files are not downloading in ios and these functions ( showNotification: true, openFileFromNotification: true,) are also not working. Is there an alternative to show download progress or openFromNotifications function for ios ?

safi50 avatar Mar 19 '22 10:03 safi50

Hello,

Any update on this matter? Not working on IOS

kareemzok avatar May 18 '22 13:05 kareemzok

hello, any update for this issue ? i not yet find the solution

ahmadsufyan455 avatar Jun 24 '22 06:06 ahmadsufyan455

Hello,

it worked from my side. As far as i can tell i added the following config :

saveInPublicStorage: true,
savedDir: ((await Helper().findLocalPath())! + "/folder_app" ),
showNotification: false,

where the findlocal function is:

  Future<String?> findLocalPath() async {
    var externalStorageDirPath;
    if (Platform.isAndroid) {
      try {
        final directory = await getExternalStorageDirectory();
        externalStorageDirPath = directory?.path;
      } catch (e) {
        final directory = await getExternalStorageDirectory();
        externalStorageDirPath = directory?.path;
      }
    } else if (Platform.isIOS) {
      externalStorageDirPath =
          (await getApplicationDocumentsDirectory()).absolute.path;
    }

    String _localPath = externalStorageDirPath! + '/folder_app';
    final savedDir = Directory(_localPath);
    bool hasExisted = await savedDir.exists();
    if (!hasExisted) {
      savedDir.create();
    }
    return externalStorageDirPath;
  }

kareemzok avatar Jun 24 '22 08:06 kareemzok

Try to add these two keys in Info.plist. Source file_saver Thanks to that I am able to see saved files on real iPhone.

<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>

MarcinHradowicz avatar Jul 07 '22 13:07 MarcinHradowicz

iOS 15.5 Virtual Machine iPhone 8 issues?

  • Android work fine, but when I using function open file current version not working =((
  • iPhone has downloaded file but file is not my expectations, my file is PDF but file download is another format (download_task.sql), So something wrong with my code?
  • Below is my code with findLocalPath() function using @kareemzok
  • FlutterDownloader.registerCallback(downloadCallback); await FlutterDownloader.enqueue( url: url, savedDir: await findLocalPath(), showNotification: true, openFileFromNotification: true, saveInPublicStorage: true, ).then((taskId) async { hideLoading(); if (taskId != null) { showMessages('Download is success!'); } });

NguyenPhatBG avatar Jul 16 '22 04:07 NguyenPhatBG