我收到此错误
$ cordovaFileTransfer.download不是函数
我的代码就是这个
app.controller('GalleryCtrl', ['$scope', '$cordovaFileTransfer', function($scope, $cordovaFileTransfer) {
$scope.testFileDownload = function () {
var url = "http://www.gajotres.net/wp-content/uploads/2015/04/logo_radni.png";
var filename = url.split("/").pop();
var targetPath = cordova.file.externalRootDirectory + filename;
alert(targetPath);
$cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) {
alert('Success!');
}, function (error) {
alert('Error!');
}, function (progress) {
// PROGRESS HANDLING GOES HERE
});
};
}])
在我的app js中,我定义了ngCordova
答案 0 :(得分:0)
安装此插件:cordova插件添加cordova-plugin-file-transfer
然后使用此代码。我希望它能满足你的要求
app.controller('GalleryCtrl', ['$scope', '$cordovaFileTransfer', function($scope, $cordovaFileTransfer) {
$scope.testFileDownload = function() {
var fileTransfer = new FileTransfer();
var url = "http://www.gajotres.net/wpcontent/uploads/2015/04/logo_radni.png";
var uri = encodeURI(url);
var filename = url.split("/").pop();
var targetPath = cordova.file.externalRootDirectory + filename;
alert(targetPath);
fileTransfer.download(uri, targetPath, function(entry) {
alert('Success!');
// PROGRESS HANDLING GOES HERE
},
function(error) {
alert(JSON.stringify(error));
},
false, {
headers : {
"Authorization" :"BasicdGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
});
};
}])