Я загружаю несколько файлов, используя метод jquery & sforce.Я хочу показать индикатор с процентом загруженного файла, но не повезло.Я использовал метод onprogress, но он вызывался один раз, даже я пытался загрузить 10 МБ файл, но предупреждающее сообщение показывается один раз (значение event.loaded & event.total совпадает), а затем файл начинает загружаться.Загрузка нескольких файлов работает хорошо, но метод прогресса - нет.Мой код:
function uploadAttachmentFile() {
sforce.connection.sessionId = "{!$Api.Session_ID}";
var input = document.getElementById("flDocuements");
var filesToUpload = input.files;
var fileCount = 1;
var fileBarWidth = $('.fileUploadProgress').width()/filesToUpload.length;
for(var i = 0, f; f = filesToUpload[i]; i++){
var reader = new FileReader();
reader.file = f;
reader.onload = function(e){
var att = new sforce.SObject("Attachment");
att.Name = this.file.name;
att.ContentType = this.file.type;
att.ParentId = parentId;
var binary = "";
var bytes = new Uint8Array(e.target.result);
var length = bytes.byteLength;
for (var i = 0; i < length; i++){
binary += String.fromCharCode(bytes[i]);
}
att.Body = (new sforce.Base64Binary(binary)).toString();
sforce.connection.create([att],{
onSuccess : function(result, source){
if (result[0].getBoolean("success")){
$('.fileUploadBar').width($('.fileUploadBar').width() + fileBarWidth);
if(fileCount == filesToUpload.length){
$('#btnFileUplaodCancel, #btnFileUplaod').attr('disabled', false);
window.close();
var documentType = "";
documentType = $("input[type=radio][name=rdDocumentType]:checked").val();
alert('documents successfully uploaded');
endSplash();
}
fileCount++;
}else{
alert('an error has occurred ' + result[0]);
}
},
onFailure : function(error, source){
// console.log("an error has occurred " + error);
$('#btnFileUplaodCancel, #btnFileUplaod').attr('disabled', false);
alert('an error has occurred ' + error);
}
});
};
reader.readAsArrayBuffer(f);
reader.onprogress = function(event) {
if (event.lengthComputable) {
alert('Received ' + event.loaded + ' of ' + event.total + 'bytes');
} else {
alert('Received ' + event.loaded + 'bytes'); // no Content-Length
}
};
} //for loop end
}
И есть кнопка, которая вызывает uploadAttachementFile ().Входной тег, который содержит несколько файлов, как показано ниже.
<span>Browse</span>
<input type="file" name="multiplefiles[]" multiple="true" id="flDocuements" class="fileInput upload" />
</div>