Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting JSON error while downloading the file from url #16

Open
lankesri opened this issue Mar 22, 2021 · 10 comments
Open

Getting JSON error while downloading the file from url #16

lankesri opened this issue Mar 22, 2021 · 10 comments

Comments

@lankesri
Copy link

lankesri commented Mar 22, 2021

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
Copy link
Owner

Please mention the exact error from ADB console.

@lankesri
Copy link
Author

lankesri commented Mar 23, 2021

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
Copy link
Owner

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
Copy link
Author

actually me working on android 7 only

@vasani-arpit
Copy link
Owner

@lankesri
Copy link
Author

will try and let you know. thank you

@lankesri
Copy link
Author

lankesri commented Mar 24, 2021

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
Copy link

maflays commented May 6, 2021

any news to solve the problem?

@vasani-arpit
Copy link
Owner

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

@muchamadiqbaal08
Copy link

muchamadiqbaal08 commented May 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants