2017-08-10 76 views
1

我使用科尔多瓦文件传输插件从远程服务器下载的JPG图片科尔多瓦文件传输的插件,一切似乎是正确的,但它不工作,我得到错误代码3 这里是我的js代码:文件下载Android版

 var uri = encodeURI(serverUrl), 
     dir = encodeURI(cordova.file.dataDirectory+'images/'+file), 
     ft = new FileTransfer(); 
     ft.download(uri, dir, 
      function (fileEntry) { 
      alert('Downloaded!'); 
      }, 
      function (error) { 
      alert('Download error'+ error.code); 
      },false, 
      { 
       headers: { 
        "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" 
      } 
     }); 

这里是我的PHP代码

//Donwload images from server 
     $app->GET('/downloadMedia/{filename}', function ($request, $response, $args) { 
      $file = 'upload/images/'.$args['filename']; 
     if(file_exists($file)) 
     { 
      $response ->withHeader('Content-Description', 'File Transfer') 
     ->withHeader('Content-Type','application/octet-stream') 
     ->withHeader('Content-Disposition', 'attachment;filename="'.basename($file).'"') 
     ->withHeader('Expires', '0') 
     ->withHeader('Content-Transfer-Encoding', 'binary') 
     ->withHeader('Cache-Control', 'must-revalidate') 
     ->withHeader('Pragma', 'public') 
     ->withHeader('Content-Length', filesize($file)); 
     readfile($file); 
     exit; 
     } 
     }); 

有人能帮助我吗?

回答

0

问题解决了,它与我的服务器网址没有关联到传输插件,因为我认为