Giter Site home page Giter Site logo

vasani-arpit / cordova-plugin-downloadmanager Goto Github PK

View Code? Open in Web Editor NEW
44.0 7.0 39.0 10.95 MB

A Cordova plugin to download file in system's default download manager

Java 80.47% JavaScript 19.53%
cordova cordova-plugin phonegap phonegap-plugin android

cordova-plugin-downloadmanager's Introduction

cordova-plugin-downloadmanager

A Cordova plugin to download file in system's default download manager

Supported Platforms

  • Android (SDK >= 11)

Installation

cordova plugin add https://github.com/vasani-arpit/cordova-plugin-downloadmanager

How to Use

//after device is ready
var fail = function (message) {    
   alert(message)
}
var success = function (data) {
       console.log("succes");
}
cordova.plugins.DownloadManager.download("Your URL to download", "Your file name","Your Description" ,success, fail);
var options = {
  setDestinationInExternalPublicDir: true  // set true if you want to use public dir instead of files dir
}
cordova.plugins.DownloadManager.download("Your URL to download", "Your file name","Your Description" ,success, fail, options)

To add an already downloaded file to the Downloads database.

// Full absolute path the the already downloaded file.  It should be in file:///storage/emulated/0/Download/ or subfolder.
const filepath_sanitized = filepath.replace("file://", "");  // Note: Don't include any file:// prefix in the path.

/**
 * Method that calls the addCompletedDownload method on the DownloadManager object
 * @param {string} title Must match the filename which was written.
 * @param {string} description doesn't seem used?
 * @param {string} mimeType i.e. "text/plain"
 * @param {string} path Absolute file path. Note: Don't include any file:// prefix in the path.
 * @param {number} length size of the downloaded file
 * @param {function(string)} success callback
 * @param {function(string)} error callback
 */
cordova.plugins.DownloadManager.addCompletedDownload(filename, "Your Description", 'text/*', filepath_sanitized, length,
  (result) => {
    console.info(result);
  },
  (err) => {
    console.error(err);
  })

Result

screenshot

If this plugin helps your project then don't forget to โญ star the repo.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

cordova-plugin-downloadmanager's People

Contributors

pabbott-lumitec avatar slidenergy avatar vasani-arpit avatar yash-oza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-downloadmanager's Issues

Add an option to configure the request.

It would be great if we could add headers to the request. I found a public method addRequestHeader(String header, String value) which can help us achieve it here.

Can we add option to change the download path? If it is possible it would be great.

Thanks.

Getting JSON error while downloading the file from url

downloaded the zip and the did Uncompress and added the plugin to current project as

cordova plugin add C:\Users\vijayavarma.l\Desktop\Temp\cordova-plugin-downloadmanager-master

And added the below code in download method

 var fail = function (message) {
       alert(message)
    }
    var success = function (data) {
           console.log("succes");
    }
    var options = {
      setDestinationInExternalPublicDir: true  // set true if you want to use public dir instead of files dir
    }
    cordova.plugins.DownloadManager.download(url, "aaaaaa","Download Successful" ,success, fail);

and finally getting below error

Getting JSON error while downloading the file from url

Please help me out. Thank you

Error while running an application

Hello,
I am getting below error while running an application.

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'download' of undefined
TypeError: Cannot read property 'download' of undefined
    at file:///android_asset/www/build/main.js:200:44
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:14976)
    at Object.zone._inner.zone._inner.fork.onInvoke (file:///android_asset/www/build/vendor.js:4979:33)
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:14916)
    at r.run (file:///android_asset/www/build/polyfills.js:3:10143)
    at file:///android_asset/www/build/polyfills.js:3:20242
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15660)
    at Object.zone._inner.zone._inner.fork.onInvokeTask (file:///android_asset/www/build/vendor.js:4970:33)
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15581)
    at r.runTask (file:///android_asset/www/build/polyfills.js:3:10834)
TypeError: Cannot read property 'download' of undefined
    at file:///android_asset/www/build/main.js:200:44
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:14976)
    at Object.zone._inner.zone._inner.fork.onInvoke (file:///android_asset/www/build/vendor.js:4979:33)
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:14916)
    at r.run (file:///android_asset/www/build/polyfills.js:3:10143)
    at file:///android_asset/www/build/polyfills.js:3:20242
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15660)
    at Object.zone._inner.zone._inner.fork.onInvokeTask (file:///android_asset/www/build/vendor.js:4970:33)
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15581)
    at r.runTask (file:///android_asset/www/build/polyfills.js:3:10834)
    at c (file:///android_asset/www/build/polyfills.js:3:19752)
    at file:///android_asset/www/build/polyfills.js:3:20273
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15660)
    at Object.zone._inner.zone._inner.fork.onInvokeTask (file:///android_asset/www/build/vendor.js:4970:33)
    at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:15581)
    at r.runTask (file:///android_asset/www/build/polyfills.js:3:10834)
    at o (file:///android_asset/www/build/polyfills.js:3:7894)defaultErrorLogger @ vendor.js:1703

Can you provide any suggestion to solve this?

Callback for download complete not available

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.