您好我正在尝试将图片上传到我的保管箱并且上传工作正常但是当我选择多张图片并将其上传到保管箱时,部分图片没有上传且错误显示
"{"error_summary": "too_many_write_operations/..", "error": {"reason": {".tag": "too_many_write_operations"}}}"
这是使用cordovafiletransfer的代码
$cordovaImagePicker.getPictures(optionsSelectImage)
.then(function(results) {
console.log(results)
for (var i = 0; i < results.length; i++) {
// console.log('Image URI: ' + results[i]);
var image = results[i];
var counter = 0;
// var filename = JSON.stringify(results[i].substr(results[i].lastIndexOf('/') + 1));
// console.log(filename)
var options = {
headers: {
'Content-Type': 'application/octet-stream',
'Authorization': 'Bearer ACCESS TOKEN',
"Dropbox-API-Arg": '{"path": "/photo.jpg", "mode": "add","autorename": true,"mute": false}'
}
}
$cordovaFileTransfer.upload('https://content.dropboxapi.com/2/files/upload', image, options)
.then(function(result) {
// Success!
counter++;
if (counter != results.length) {
$ionicLoading.show({
//Loading Content
template: '<ion-spinner icon="android"></ion-spinner><br><center>Uploading ' + counter + ' /' + results.length + ' to Dropbox</center>'
});
}
// if number of files uploaded in the dropbox == total number of queued files for uploading
else if (counter === results.length) {
$ionicLoading.hide();
}
console.log(result)
}, function(err) {
// Error
console.log(err)
}, function(progress) {
});
我认为for循环对于进程来说太快了,为什么dropbox会处理它?我怎样才能减慢速度或延迟上传
答案 0 :(得分:0)
可能你是在同一时间上传所有内容,更好的解决方案是成对或逐个上传图片,将这样的承诺链接起来:
var promiseChain = Q.fcall(function() {});
results.forEach(function(filename) {
var promiseLink = function() {
var def = Q.defer();
$cordovaFileTransfer.upload('...', filename).then(function(result) {
// do stuff
setTimeout(function(){
def.resolve();
}, delay)
});
return def.promise;
};
promiseChain = promiseChain.then(promiseLink);
});
promiseChain();