【发布时间】:2016-11-18 23:47:22
【问题描述】:
我正在开发一个程序,我想在 android 设备中保存一个 pdf blob。 这是回调中的服务器端代码,它接收 pdf 数据作为“结果”。
var file = new Blob([result.data], {
type: 'application/pdf;charset=utf-8;'
});
return file;
});
在客户端,以下代码在chrome调试浏览器中运行,pdf下载成功。但是在设备上我收到以下错误:
11-18 18:13:27.255 10504-10707/? D/FileTransfer: download blob:file:///e9088aac-8525-4071-9280-164a6e15c22e to file:///storage/emulated/0/Download/loanContract_11-10-2016_9-29-59-715.pdf
11-18 18:13:27.255 10504-10707/? E/FileTransfer: Unsupported URI: blob:file:///e9088aac-8525-4071-9280-164a6e15c22e
这里window.URL.createObjectURL(data)中的数据是服务器返回的文件blob。 Phonegap/Cordova 3.6 - Download of file through blob:file 没有帮助我解决问题。
var fileURL = window.URL.createObjectURL(data);
$scope.content = data;
a.href = fileURL;
a.download = fileName;
a.click();
console.log("Inside parent function");
$scope.fileName = fileName;
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (dirEntry) {
download($scope.fileURL, dirEntry.toURL()+'Download/'+ $scope.fileName) ;
}, function () {} );
var download = function ( uri, fileURL) {
$cordovaFileTransfer.download(
uri,
fileURL,
function (success) {
console.log(success);
},
function (err) {
console.log(err);
}, true)
};
如果我提供一个将 pdf 文件作为 HTTP 响应发送的 url,并且我将 API 的 URL 作为参数 uri 提供给 cordovaFileTransfer.download,那么 pdf 将被保存。 请帮我将此鲍勃保存为设备上的 pdf。
【问题讨论】: