使用适用于安卓的科尔多瓦文件传输插件下载文件



我正在使用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;
}
});

有人可以帮助我吗?

问题解决了,它与我的服务器 url 有关,而不是我想象的传输插件

最新更新