最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error code 1 cordova plugin file transfer android - Stack Overflow

programmeradmin1浏览0评论

I have a problem on cordova (android), when I try to download a file (a .zip exactly), It always occured a error code 1. The url downloads well on my computer. Here is the code :

    let fileTransfer = new FileTransfer();
      url = encodeURI(url);

      fileTransfer.download(
        url,
        cordova.file.externalApplicationStorageDirectory,
        function(entry) {
          console.log('download complete: ' + entry.toURL());
        },
        function(error) {
          console.log('download error source ' + error.source);
          console.log('download error target ' + error.target);
          console.log('upload error code is ' + error.code);
        });

Thanks

I have a problem on cordova (android), when I try to download a file (a .zip exactly), It always occured a error code 1. The url downloads well on my computer. Here is the code :

    let fileTransfer = new FileTransfer();
      url = encodeURI(url);

      fileTransfer.download(
        url,
        cordova.file.externalApplicationStorageDirectory,
        function(entry) {
          console.log('download complete: ' + entry.toURL());
        },
        function(error) {
          console.log('download error source ' + error.source);
          console.log('download error target ' + error.target);
          console.log('upload error code is ' + error.code);
        });

Thanks

Share Improve this question asked May 31, 2016 at 16:12 Basile BeldameBasile Beldame 4301 gold badge4 silver badges16 bronze badges 3
  • 1 Error code as per plugin documentation is "NOT_FOUND_ERR" which means the requested resource is not found. Ensure the resource is available and also ensure you have added Cordova whitelist plugin to make CORS request – Gandhi Commented May 31, 2016 at 17:03
  • It wasn't the problem, but thank you for taking time to help me – Basile Beldame Commented May 31, 2016 at 19:04
  • Glad it worked. Looks like not found error meant file not found in device to write I guess. – Gandhi Commented May 31, 2016 at 19:07
Add a comment  | 

2 Answers 2

Reset to default 19

The error was that I forgot to specify the name of the file when it will be downloaded on the device, I didn't know I had to specify that. So here is the corrected code (modifications at lign 6) :

  let fileTransfer = new FileTransfer();
  url = encodeURI(url);

  fileTransfer.download(
    url,
    cordova.file.externalApplicationStorageDirectory+'whatever.png',
    function(entry) {
      console.log('download complete: ' + entry.toURL());
    },
    function(error) {
      console.log('download error source ' + error.source);
      console.log('download error target ' + error.target);
      console.log('upload error code is ' + error.code);
    });
  1. Make sure path of target file ( downloaded file ) is valid.
  2. Make sure target file name is valid.
  3. Make sure download file path is valid.

Code 1 corresponds to FileTransferError.FILE_NOT_FOUND_ERR

发布评论

评论列表(0)

  1. 暂无评论