Flex 3 多次上传进度监控

发布于 2024-08-05 10:51:22 字数 238 浏览 3 评论 0原文

我有一个 Flex3 应用程序,它必须能够上传多个文件并使用标签而不是进度条监视每个文件的单独进度。

我的问题是,上传的通用进度处理程序无法(据我所知)指示正在进行的上传。我知道可以检查文件名,但在此应用程序中,多次上传的文件名可能相同。

我的问题:使用通用进度处理程序如何区分具有相同文件名的 2 个多个上传?

编辑:回答者可能会认为我是 Flex 的新手...因为我确实是。

I have a Flex3 application which has to be capable of uploading multiple files and monitoring each files individual progress using a label NOT a progress bar.

My problem is that a generic progress handler for the uploads has no way (that I know of) of indicating WHICH upload it is that is progressing. I know that a file name is available to check but in the case of this app the file name might be the same for multiple uploads.

My question: With a generic progress handler how does one differentiate between 2 multiple uploads with the same file name?

EDIT: answerers may assume that I am a total newb to Flex... because I am.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把时间冻结 2024-08-12 10:51:22

我使用这个:

  private function _addFileListeners(dispatcher:IEventDispatcher):void {
      dispatcher.addEventListener(Event.OPEN, this._handleFileOpen);
        dispatcher.addEventListener(Event.SELECT, this._handleFileOpen);
        dispatcher.addEventListener(Event.CANCEL, this._handleFileCancel);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, this._handleFileProgress);
        dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,this._handleFileComplete);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, this._handleError);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._handleError);
    }

其中“调度程序”是文件:

        for (var i:uint = 0; i < fileList.length; i++) {
            file = FileReference(fileList[i]);
            this._addFileListeners(file);
            this._pendingFiles.push(file);
        }

和示例处理程序:

    private function _handleFileOpen(e:Event):void {
        var file:FileReference = FileReference(e.target);
        ...
    }

我不确定您希望如何区分具有相同名称的两个文件。就我而言,我将文件放入队列中发送。所以一次只能上传 1 个文件。 (待处理文件)。

I use this:

  private function _addFileListeners(dispatcher:IEventDispatcher):void {
      dispatcher.addEventListener(Event.OPEN, this._handleFileOpen);
        dispatcher.addEventListener(Event.SELECT, this._handleFileOpen);
        dispatcher.addEventListener(Event.CANCEL, this._handleFileCancel);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, this._handleFileProgress);
        dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,this._handleFileComplete);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, this._handleError);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._handleError);
    }

where "dispatcher" is the file:

        for (var i:uint = 0; i < fileList.length; i++) {
            file = FileReference(fileList[i]);
            this._addFileListeners(file);
            this._pendingFiles.push(file);
        }

and a sample handler:

    private function _handleFileOpen(e:Event):void {
        var file:FileReference = FileReference(e.target);
        ...
    }

I'm not sure how you want to differentiate between two files with the same name. In my case, I send the files in a queue. So there's only ever 1 file being uploaded at a time. (pendingFiles).

入画浅相思 2024-08-12 10:51:22

如果您正在侦听 ProgressEvents,这些事件有一个 currentTarget 属性,该属性将引用已注册事件侦听器的对象。

我假设您首先知道每个对象对应哪个文件上传对象。

编辑:使用 FileReference 的示例:

import flash.net.FileReference;
import flash.events.ProgressEvent;
import flash.utils.Dictionary;

public var files:Dictionary = new Dictionary();     // This will hold all the FileReference objects

public function loadFile(id:String):void
{
    var file:FileReference = new FileReference();

    // Listen for the progress event on this FileReference... will call the same function for every progress event
    file.addEventListener(ProgressEvent.PROGRESS, onProgress);

    // TODO: listen for errors and actually upload a file, etc.

    // Add file to the dictionary (as key), with value set to an object containing the id
    files[file] = { 'id': id };
}

public function onProgress(event:ProgressEvent):void
{
    // Determine which FileReference dispatched thi progress event:
    var file:FileReference = FileReference(event.target);

    // Get the ID of the FileReference which dispatched this function:
    var id:String = files[file].id;

    // Determine the current progress for this file (in percent):
    var progress:Number = event.bytesLoaded / event.bytesTotal;

    trace('File "' + id + '" is ' + progress + '% done uploading');
}


// Load some files:
loadFile('the first file');
loadFile('the second file');

If you are listening for ProgressEvents, these events have a currentTarget attribute that would have a reference to the object that has registered the event listener.

I'm assuming you know which file-uploading object goes with each object in the first place.

EDIT: Example using FileReference:

import flash.net.FileReference;
import flash.events.ProgressEvent;
import flash.utils.Dictionary;

public var files:Dictionary = new Dictionary();     // This will hold all the FileReference objects

public function loadFile(id:String):void
{
    var file:FileReference = new FileReference();

    // Listen for the progress event on this FileReference... will call the same function for every progress event
    file.addEventListener(ProgressEvent.PROGRESS, onProgress);

    // TODO: listen for errors and actually upload a file, etc.

    // Add file to the dictionary (as key), with value set to an object containing the id
    files[file] = { 'id': id };
}

public function onProgress(event:ProgressEvent):void
{
    // Determine which FileReference dispatched thi progress event:
    var file:FileReference = FileReference(event.target);

    // Get the ID of the FileReference which dispatched this function:
    var id:String = files[file].id;

    // Determine the current progress for this file (in percent):
    var progress:Number = event.bytesLoaded / event.bytesTotal;

    trace('File "' + id + '" is ' + progress + '% done uploading');
}


// Load some files:
loadFile('the first file');
loadFile('the second file');
十级心震 2024-08-12 10:51:22

我最终创建了自己的类来管理每个上传文件的事件

I ended up creating my own class that manages events for each uploading file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文