Javascript 在angular cordova应用程序中的一个请求中发布多个文件
在每个位置搜索解决方案,因为我的应用程序联系人需要在一个请求中发布所有文件 我的当前代码:->-angularjs 1.5.3-Javascript 在angular cordova应用程序中的一个请求中发布多个文件,javascript,android,angularjs,cordova,Javascript,Android,Angularjs,Cordova,在每个位置搜索解决方案,因为我的应用程序联系人需要在一个请求中发布所有文件 我的当前代码:->-angularjs 1.5.3- app.service('siUpload',function($q){ //... this.upload(imageURI,url){ var deferred = $q.defer(); //.. etc.. options and other stuff var ft = new FileTransfer(); ft.upload(ima
app.service('siUpload',function($q){
//...
this.upload(imageURI,url){
var deferred = $q.defer();
//.. etc.. options and other stuff
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(url),deferred.resolve,deferred.reject);
return deferred.promise
}
})
在控制器中,我可以循环选择的文件并逐个上传
angular.forEach($scope.files,function(f){
siUpload.upload(f.url,$server+'blog/'+e.grouping+'/file')
});
这非常有效,但服务器需要在一个请求中以名称file[]
发送所有文件
在我使用angular lib ngFileUpload之前,由于input type=file:()中的webview错误,它在android 4.4.2上不再工作
那么,cordova file transfer是否可以在一个请求中发送多个文件?或者甚至可以使用本机xhr在一个请求中上载多个文件?因为我没有得到答案,而且有几次投票,所以我最终解决了这个问题 注意我使用的是angularjs 1.x
$scope.capture = function(){
siUpload.pickFile().then(
function(r){
//r contain thumbnails and form data
$scope.thumbnails = r[0];
var fd = r[1];
angular.forEach($scope.post,function(val,key){
fd.append(key,val); //adding extra paramters to the post request
});
//POSTING All FILES and data in one request :)
$http.post('API://blog', fd, {
headers: {'Content-Type': undefined },
transformRequest: angular.identity
});
});
}
希望这对未来的谷歌用户有所帮助:-)
$scope.capture = function(){
siUpload.pickFile().then(
function(r){
//r contain thumbnails and form data
$scope.thumbnails = r[0];
var fd = r[1];
angular.forEach($scope.post,function(val,key){
fd.append(key,val); //adding extra paramters to the post request
});
//POSTING All FILES and data in one request :)
$http.post('API://blog', fd, {
headers: {'Content-Type': undefined },
transformRequest: angular.identity
});
});
}