【问题标题】:File download with cordova file transfer plugin for android使用适用于 android 的 cordova 文件传输插件下载文件
【发布时间】:2017-08-14 19:01:15
【问题描述】:

我正在使用 cordova 文件传输插件从远程服务器下载 jpg 图像,一切似乎正确但它不起作用,我收到错误代码 3。 这是我的js代码:

      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;
        }
      });

有人可以帮我吗?

【问题讨论】:

    标签: android cordova cordova-plugins file-transfer


    【解决方案1】:

    问题解决了,它与我的服务器 url 相关,而不是我认为的传输插件

    【讨论】:

      猜你喜欢
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2018-02-17
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      相关资源
      最近更新 更多