vasani-arpit / cordova-plugin-downloadmanager

A Cordova plugin to download file in system's default download manager
44 stars 38 forks source link

Callback for download complete not available #5

Open fabrz opened 6 years ago

fabrz commented 6 years ago

Hi,

Is there a way to open the downloaded file as soon as it's been downloaded? I'm trying to rely on the success callback but it looks like that method gets fired before the download it's complete.

Hence why I can't find the file in the Download folder of the device yet. I'll share some code with you so you can get a better understanding of it.

  updateAndroidApp(url) {
    const fileName = url.substring(url.lastIndexOf('/') + 1);

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (fileSystem) => { // eslint-disable-line
      const onDownloadFailure = (message) => { // eslint-disable-line
        // @todo: handle the error message
      };

      const onDownloadSuccess = (data) => { // eslint-disable-line
        const fileURL = `${window.cordova.file.externalDataDirectory}Download/${fileName}`;
        fileOpener.open(fileURL);
      };

      window.cordova.plugins.DownloadManager.download(url, onDownloadSuccess, onDownloadFailure);
    });
  }

Cheers

vasani-arpit commented 6 years ago

The success is in the sense of successfully started downloading that means Plugin has successfully tell OS to start downloading this particular file.

The feature you are asking for is yet to be added to the plugin.

ramoncarreras commented 5 years ago

This is implemented in the PULL REQUEST https://github.com/vasani-arpit/cordova-plugin-downloadmanager/pull/2

Unfortunately, it has never been merged.

vasani-arpit commented 5 years ago

Yes. I am occupied with other projects. I'll make time for this one.

ramoncarreras commented 5 years ago

OK @vasani-arpit. Thanks.

asoap commented 5 years ago

If I'm reading this correctly, the PR is for something else. addCompletedDownload let's you just tell the DownloadManager to add a file. I'm currently using it, but it's getting all screwed up for me, as any file I add isn't able to be opened.

https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String,%20java.lang.String,%20boolean,%20java.lang.String,%20java.lang.String,%20long,%20boolean)