ngCordova FileTransfer从FTP下载文件时返回http_status:null
ngCordova FileTransfer returning http_status: null when downloading file from FTP
我正试图使用Cordova从FTP服务器下载一个文件。我安装了ngCordova和文件传输插件。以下是我的代码:
angular.module('TestApp', ['ionic', 'TestApp.controllers', 'charts.ng.justgage', 'pascalprecht.translate', 'ngCookies', 'ngCordova'])
var app = angular.module('TestApp.controllers', [])
app.controller('FileDownloadCtrl', function($scope, $timeout, $cordovaFileTransfer) {
$scope.downloadFile = function() {
var url = "ftp://URL/somefile.xml";
var filename = url.split("/").pop();
alert(filename);
var targetPath = cordova.file.externalRootDirectory + filename;
var trustHosts = true;
var options = new Object();
var headers = { 'Authorization': 'Basic Login_cred' };
options.headers = headers;
alert(cordova.file.externalRootDirectory);
alert(options.headers);
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
// Success!
alert(JSON.stringify(result));
}, function(error) {
// Error
alert(JSON.stringify(error));
}, function (progress) {
$timeout(function () {
$scope.downloadProgress = (progress.loaded / progress.total) * 100;
})
});
}
});
Angular.module位于实际代码中的另一个JS文件中
此代码返回以下警报:
- somefile.xml
- file://storage/emulated/0/
- [对象对象]
- {"代码":2,"源":ftp://URL/somefile.xml","target":file:///storage/emulated/0/somefile.xml","http_status":null,"body":null、"exception":null}
我尝试从ftp上托管的网站下载文件(http://website/somefile.xml),效果很好。我很确定我的头球有问题。我还尝试将Login_creds放入目标url,如下所示:ftp://username:password@URL/somefile.xml,这不起作用,但它可能是特定于浏览器的。
ngCordova File Transfer不适用于ftp://URL,当我切换到受密码保护的http解决方案时,它起作用了。
相关文章:
- Meteor如何接收HTTP请求
- 在我的情况下,如何进行http请求
- //而不是在src=“”上使用http://"属性
- 我无法使用angularJs($http)访问服务器
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- 如何将PHP get查询转换为Meteor's HTTP.get()
- 角度异步http自动完成
- 什么's本地node.js服务器和python简单http服务器之间的区别
- 角度http服务器页面刷新404s
- http.listen()在运行时接受终端命令
- IIS动态HTTP响应标头
- spring和angularJS(我得到了类似HTTP状态404的错误)
- 存储$http如何从$http函数(Angularjs)外部获取可访问变量中的响应
- Typescript angularjs$http获取响应类型(避免使用<any>)
- 如何从HTTP上下文对象中获取Post数据
- GWT应用程序中出现错误HTTP 404(“Script Tag Failure-no status available
- Spring MVC中的PUT方法HTTP Status 400-AngularJS
- 如何获取casper.js http.status代码
- Internet Explorer Internet Failure HTTP Status Codes
- jqXHR - http-status-code-403 (but the statuscode is 0)