我想上傳文件夾中的圖像列表,並將它們作爲字節流存儲在數據庫中。我想給包含圖像的文件夾,而不是選擇多個文件。下面給出負責編碼的部分。上傳文件夾中的圖像列表AngularJs
$scope.uploadMultipleQuestions = function(e) {
var questionList = []
var difficultyLevel = vm.question.difficultyLevel;
var theFiles = e.files;
for (var i = 0; i < theFiles.length; i++) {
var ques = {};
ques.questionString = theFiles[i].name;
DataUtils.toBase64(theFiles[i], function(base64Data) {
$scope.$apply(function() {
ques.questionImage = base64Data;
});
[![enter image description here][1]][1]
});
ques.questionImageContentType = theFiles[i].type;
ques.questionString = theFiles[i].webkitRelativePath.split("/")[1];
questionList.push(ques);
Question.uploadMultipleQuestions(questionList);
}
for (var i = 0; i < questionList.length; i++) {
console.log(questionList[i]);
}
//Question.uploadMultipleQuestions(questionList);
}
正如你所看到的只是最後的對象包含圖像數據,而沒有其他人有任何圖像內容。
讓我知道爲什麼會出現這個問題,以及如何解決這個問題。
參見[如何使用Java腳本來打印文件夾內的所有TXT文件(http://stackoverflow.com/questions/37634049/how-to-print-all-the-txt-files-inside -a-文件夾使用的Java腳本)。 DataUtils.toBase64'是否異步返回結果? – guest271314