Blueimp file upload, how do you know which file the progress callback is for?

拥有回忆 提交于 2019-12-05 17:59:16

The 'fileuploadprogress' callback includes data.context. This is a jquery object of the markup that you might have created in the 'fileuploadadd' callback.

You can add a progress element (or any other markup to provide feedback) in the 'fileuploadadd' callback, then find it again in the 'fileuploadprogress' and set the progress:

.on('fileuploadadd', function (e, data) {
    $.each(data.files, function (index, file) {
        data.context = $('<div/>', { class: 'pull-left text-center media_wrapper' }).appendTo('#thumbnails');
        $('<progress>', { value: '0', max: '100'}).appendTo(data.context)
    });
})
/* ... */
.on('fileuploadprogress', function (e, data) {
    if (data.context) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        data.context.find('progress').attr('value', progress);
    }
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!