首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在SWFUpload中重置队列?

如何在SWFUpload中重置队列?
EN

Stack Overflow用户
提问于 2011-05-30 12:35:02
回答 2查看 4.4K关注 0票数 1

我已经下载了SWFUpload,希望通过我的网站创建上传大型文件的功能。

我找到了一个指南:http://webdeveloperplus.com/jquery/multiple-file-upload-with-progress-bar-using-jquery/,我认为我可以从它开始。不同的是,我只想一次只上传一张图片。,但我不知道如何在上传了一个文件后恢复SWFUpload?,我希望队列被重置,进度条被取消。

调试说明:SWF DEBUG: Event: uploadError : Upload limit reached. No more files can be uploaded.

下面是我的SWFUpload代码:

代码语言:javascript
复制
$(function()
{
    $('#swfupload-control').swfupload({
          upload_url                : "upload-file.php"
        , file_post_name            : 'uploadfile'
        , file_size_limit           : "102400" // 100 MB
        , file_types                : "*.jpg;*.png;*.gif"
        , file_types_description    : "Image files"
        , file_upload_limit         : 1
        , flash_url                 : "js/swfupload/swfupload.swf"
        , button_image_url          : 'js/swfupload/wdp_buttons_upload_114x29.png'
        , button_width              : 114
        , button_height             : 29
        , button_placeholder        : $('#button')[0]
        , debug                     : true
    })
    .bind('fileQueued', function(event, file)
    {
        var listitem='<li id="'+file.id+'">'+
            '<span class="progresstext"><span class="progressvalue"></span> '+file.name+'</span>'+
            '<div class="progressbar"><div class="progress"></div></div>'+
            '</li>';
        $('#log').append(listitem);
        // start the upload since it's queued
        $(this).swfupload('startUpload');
    })
    .bind('fileQueueError', function(event, file, errorCode, message)
    {
        alert('Size of the file '+file.name+' is greater than limit');
    })
    .bind('uploadStart', function(event, file)
    {
        $('#log li#'+file.id).find('span.progressvalue').text('0%');
    })
    .bind('uploadProgress', function(event, file, bytesLoaded)
    {
        //Show Progress
        var percentage = Math.round((bytesLoaded/file.size)*100);
        $('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
        $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
    })
    .bind('uploadSuccess', function(event, file, serverData)
    {
        var item = $('#log li#'+file.id);
        item.find('div.progress').css('width', '100%');
        item.find('span.progressvalue').text('100%');
    })
    .bind('uploadComplete', function(event, file)
    {
        // upload has completed, try the next one in the queue
        $(this).swfupload('startUpload');
    })

});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-30 14:49:47

如果您正在处理上载队列,则使用swfupload.queue插件要简单得多。

然后,您可以在swfupload对象上绑定'queueComplete‘事件,一旦处理完整个队列,就会触发它(这就是您希望隐藏进度条并重置队列的地方)。为了重置队列,这个插件还添加了一个cancelQueue()函数(注意您在哪里调用它,因为它会取消任何正在进行的上传)。

如果您想手动取消它/不使用这个插件,您必须逐个取消文件,直到stats()对象表示它是空的。

代码语言:javascript
复制
// request your stat objects, it contains amongst others the number of files in the queue
var stats = my_upload.getStats();
// while the queue is not empty ...
while (stats.files_queued > 0) {
  // .. cancel the first in the queue (null: take the first found, false: don't trigger an error event)
  my_upload.cancelUpload(null, false);
  // it is important to reload the stats everytime and not just do a for (i = 0; i < stats.files_queued ...
  stats = my_upload.getStats();
}
票数 3
EN

Stack Overflow用户

发布于 2013-06-19 08:12:05

我想你的意思是“上传后如何重置统计信息?”

在某些时候,例如您已经将file_upload_limit设置为1,您上传了一个文件,但在此之后删除了它,您需要重置统计信息,否则就不能继续上传任何文件。

现在,您可以编写如下代码:

代码语言:javascript
复制
  var stats = swfUploadObj.getStats();
  stats.successful_uploads = stats.successful_uploads - 1;
  swfUploadObj.setStats(stats);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6176357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档