它總是上傳第一個文件在一個數組 餘米遍歷圖像文件的列表,用於發送它們通過HTTP上傳如何在一個文件列表中以循環的角度做同步http請求?
for(var j=0;j<images.length;j++){
(function(idx,images){
console.log("idx"+JSON.stringify($scope.Files)+"====="+JSON.stringify(images));
var data = {"image":images[idx]};
var payload = new FormData();
for(var key in data){
payload.append(key, data[key]);
}
$http({
url: uploadUrl,
method: 'POST',
data: payload,
//assign content-type as undefined, the browser
//will assign the correct boundary for us
headers: {'token':token,'Access-Control-Allow-Origin': '*','Content-Type': undefined},
//prevents serializing payload. don't do it.
transformRequest: angular.identity
}).then(fucntion(response){
console.log("response :" + JSON.stringify(response));
});
})(j,images);
}
所以你想要從圖像數組順序發送http請求(uploadUrl - POST)? – CodingFreak
是的,幫我這個 –
可能重複[AngularJS鏈承諾依次在for循環](http://stackoverflow.com/questions/41272992/angularjs-chain-promises-sequentially-within-for-loop) – CodingFreak