vasani-arpit / cordova-plugin-downloadmanager

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

Getting JSON error while downloading the file from url #16

Open lankesri opened 3 years ago

lankesri commented 3 years ago

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

vasani-arpit commented 3 years ago

Please mention the exact error from ADB console.

lankesri commented 3 years ago

this is what im getting in console "Uncaught TypeError: Cannot read property 'download' of undefined"

It seems your download method is accepting JSONArray args, CallbackContext callbackContext

then how can we call like this

cordova.plugins.DownloadManager.download(url, "pdf","Download Successful" ,success, fail);

Thank you

vasani-arpit commented 3 years ago

It comes to my attention that this plugin is not supported in Android 10 and 11. Try out in lower version and let me know how that goes.

lankesri commented 3 years ago

actually me working on android 7 only

vasani-arpit commented 3 years ago

Try this plugin https://ionicframework.com/docs/native/downloader

lankesri commented 3 years ago

will try and let you know. thank you

lankesri commented 3 years ago

Hi Vasani-arpit, file is downloading but there is no progressbar in notification section Please find the code here

 var request = {
    //Location of the resource to download
    uri: url,
    //Title of this download, to be displayed in notifications
    title: 'Downloading',
    //Description of this download, to be displayed in notifications
    description: 'pdf download',
    //This will override the content type declared in the server's response.
    mimeType: '',
    //Set whether this download should be displayed in the system's Downloads UI. True by default
    visibleInDownloadsUi: true,
    //Control when a system notification is posted by the download manager.
    notificationVisibility: 0,
    // Set the local destination to a path within the application's external files directory
    /*destinationInExternalFilesDir: {
        dirType: 'Downloads',
        subPath: '' //Path within the external directory, including the destination filename
    },*/
    //Set the local destination to a path within the application's public external storage directory
    destinationInExternalPublicDir: {
        dirType: 'Downloads',
        subPath: '' //Path within the external directory, including the destination filename
    },
    //Set the local destination for the downloaded file.
    //destinationUri: '',
    //Additional HTTP headers to be included with the download request.
    //headers: [{header: 'Authorization', value: 'Bearer iaksjfd89aklfdlkasdjf'}]
  };

cordova.plugins.Downloader.download(request,
        (location) => { alert('File is downloaded at' + location) },
        (err) => { alert(err)})
maflays commented 3 years ago

any news to solve the problem?

vasani-arpit commented 3 years ago

Unfortunately no, Use this one if possible --> https://ionicframework.com/docs/native/downloader

muchamadiqbaal08 commented 2 years ago

show alert json error is an error while you used without option , i'm already used this plugin in my project and it work fine