File upload 带拖放功能的OpenLaszlo图像上传组件;删除支持和预览

File upload 带拖放功能的OpenLaszlo图像上传组件;删除支持和预览,file-upload,drag-and-drop,flash,dhtml,openlaszlo,File Upload,Drag And Drop,Flash,Dhtml,Openlaszlo,我还没有看到任何好的OpenLaszlo文件上传组件。是否有文件上传组件的开源版本,支持DHTML和AdobeAIR的拖放功能,以及两种运行时的预览功能 从技术上讲,可以支持以下功能: 在DHTML中为所有桌面浏览器拖放文件上载 DHTML中Webkit浏览器和Firefox的图像预览,以及使用SWF运行时的所有浏览器的图像预览 对AdobeAIR应用程序的拖放支持 可能有人有一个现有组件可以开源,并由社区维护或改进。目前无法在OpenLaszlo应用程序的DHTML(又名HTML5)模式下

我还没有看到任何好的OpenLaszlo文件上传组件。是否有文件上传组件的开源版本,支持DHTML和AdobeAIR的拖放功能,以及两种运行时的预览功能

从技术上讲,可以支持以下功能:

  • 在DHTML中为所有桌面浏览器拖放文件上载
  • DHTML中Webkit浏览器和Firefox的图像预览,以及使用SWF运行时的所有浏览器的图像预览
  • 对AdobeAIR应用程序的拖放支持

可能有人有一个现有组件可以开源,并由社区维护或改进。

目前无法在OpenLaszlo应用程序的DHTML(又名HTML5)模式下进行文件上载,因为不幸的是,无法在该运行时将表单类型设置为enctype=multipart/form data

但是,您可以通过访问低级flashapi,使用OpenLaszlo应用程序的SWF(Flash)模式进行文件上传。这是不明显的如何做到这一点,所以我写了一个类来做到这一点,我自己一段时间前,它将工作在(闪存)SWF8,SWF9和SWF10模式的OpenLaszlo

我从未尝试过将OpenLaszlo应用程序编译到AIR,但我相信Flash上传可能也适用于这种情况

这是我的课程,请随意使用:

(代码也可在此处找到:)



我看到了OpenLaszlo 4.9的现有组件,这在本文中提到。正如文档所述:“一个使用Flash 8文件上传api上传单个文件的类。这只适用于swf8运行时,即lzr=swf8。”这意味着,即使对于OpenLaszlo 4.9,DHTML和SWF10运行时也没有可用的文件上传组件的工作版本。如果没有更新的组件,OpenLaszlo 5.0将不支持直接上传文件。太好了,我稍后会尝试代码。关于DHTML文件上传,即使OpenLaszlo不支持enctype=multipart/form数据,也应该可以编写一个自定义JavaScript类来处理上传。这是LFC中数据集类的一个限制吗?我曾经在OpenLasZLo论坛上问过这个问题,它的回答是除非你知道如何修改OpenLasZLO的内部基础类(主要是原始的OL创建者做的),否则不可能在HTML5/DHTML模式中从OpenLasZLO中做到这一点:[Link ]你可以尝试设置你的应用程序,调用外部JavaScript,通过回调上传到应用程序中,但设置起来有点棘手。我有一个HTML5文件上传组件,在OpenLaszlo中工作,具有拖放和图像预览功能。使用数据集无法工作,您必须创建自己的组件来上载图像数据。因为我是为客户做这项工作的,所以我无法贡献代码。您是如何创建该组件的?这是一个自定义JavaScript库吗?不,它是一个OpenLaszlo库,直接调用Flash API(在OpenLaszlo中通常不访问Flash API)
<library>

<switch>

  <when property="$as3"><!-- SWF9/SWF10 -->

    <!---
    CLASS: <fileuploadhelper>
    EXTENDS: <node> (lz.node)

    DESCRIPTION:

    This is the ActionScript3 (AS3) (SWF9/SWF8) version of the Flash file
    upload object.

    This allows users to upload files when compiled to a Flash Version that
    uses ActionScript3 such as Flash 9 or Flash 10.
    -->
    <class name="fileuploadhelper" extends="node">

      <!---
      @param string uploadurl: (optional) default upload url to use if none
                               passed to this.upload()
      -->
      <attribute name="uploadurl" type="string" />

      <!-- @keywords private -->
      <!--- @param flash.net.FileReference file_reference: Flash file reference object -->
      <attribute name="file_reference" type="expression" value="null" />

      <!-- Imports Required for SWF9/SWF10 -->

      <passthrough>
        import flash.net.FileReference;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        import flash.events.IOErrorEvent;
        import flash.events.SecurityErrorEvent;
        import flash.net.URLRequest;
      </passthrough>

      <!-- *** METHODS *** -->

      <handler name="oninit">
      <![CDATA[

        #passthrough  {
           this.file_reference = new FileReference();

           file_reference.addEventListener(Event.SELECT,this.onSelect);
           file_reference.addEventListener(Event.COMPLETE, this.onComplete);
           file_reference.addEventListener(ProgressEvent.PROGRESS, this.progressHandler);
           file_reference.addEventListener(IOErrorEvent.IO_ERROR, this.ioErrorHandler);
           file_reference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.securityErrorHandler);

        }#

      ]]>
      </handler>

      <!---
      Displays file browsing window and allows the user to select a file (or
      cancel to close the window).
      -->
      <method name="browse">
      <![CDATA[

        #passthrough  {
           file_reference.browse();
        }#

      ]]>
      </method>

      <!---
      Return name of selected file

      @returns string: the filename of the selected file
      -->
      <method name="getName">
        return this.file_reference.name;
      </method>

      <!--- @keywords private -->
      <!---
      @param string submit_url: SWF9/10 #passthrough{...} requires URL to be
                                referenced in an attribute rather than a
                                locally defined OpenLaszlo variable or
                                a compilation error occurs.
      -->
      <attribute name="submit_url" type="string" />

      <!---
      Uploads the currently selected file.

      @param string strURL: (optional) If defined upload the file to this
                            URL, otherwise upload to this.uploadurl

                            Note: required if this.uploadurl is not defined.
      -->
      <method name="upload" args="strURL = false">
      <![CDATA[

        if (strURL === false)
          var strURL = this.uploadurl; // workaround for SWF9/10 compatibility

        this.setAttribute('submit_url', strURL);

        #passthrough  {
           var request:URLRequest = new URLRequest(submit_url);
           file_reference.upload(request);
        }#

      ]]>
      </method>


      <!-- * ABSTRACT handlers: Override to do something useful in instance * -->


      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when user selects a file.

      @param flash.events.Event ev: the select event
      -->
      <method name="onSelect" args="ev=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onSelect(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when progress event is captured.

      @param {anything} objDummy: SWF8 requires file_reference object here, does nothing in SWF9/10
      @param number bytesLoaded: the number of bytes of the file uploaded
      @param number bytesTotal: the number of total bytes of the file to be uploaded
      -->
      <method name="onProgress" args="objDummy, bytesLoaded, bytesTotal">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onProgress(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when a file upload is complete.

      @param flash.events.Event ev: the complete event
      -->
      <method name="onComplete" args="ev=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onComplete(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when the file upload fails.

      @param flash.events.IOErrorEvent/flash.events.securityErrorEvent ev: the Flash Error Event
      -->
      <method name="onError" args="ev=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onError(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>


      <!-- * Internal Private Handlers * -->


      <!--- @keywords private -->
      <!---
      This will pass the progress values to method this.onProgress()

      @param flash.events.ProgressEvent ev: the Flash Progress Event
      -->
      <method name="progressHandler" args="ev=null">
        this.onProgress(false, ev.bytesLoaded, ev.bytesTotal);
      </method>

      <!--- @keywords private -->
      <!---
      This will catch an ioError and call method this.onError()

      @param flash.events.IOErrorEvent ev: the Flash Error Event
      -->
      <method name="ioErrorHandler" args="ev=null">
        if ($debug) Debug.error('as3 (SWF9/10): fileuploadhelper.ioErrorHandler(): ERROR: ioError detected, could not upload file.');
        this.onError(ev);
      </method>

      <!--- @keywords private -->
      <!---
      This will catch a securityError and call method this.onError()

      @param flash.events.securityErrorEvent ev: the Flash Error Event
      -->
      <method name="securityErrorHandler" args="ev=null">
        if ($debug) Debug.error('as3 (SWF9/10): fileuploadhelper.securityErrorHandler(): ERROR: securityError detected. Are you sure you are uploading to same domian as this application is being served from?');
        this.onError(ev);
      </method>

    </class>

  </when>

  <when property="$as2"><!-- SWF8 -->

    <!---
    CLASS: <fileuploadhelper>
    EXTENDS: <node> (lz.node)

    DESCRIPTION:

    This is the ActionScript2(AS2) (SWF8) version of the Flash file
    upload object.

    This allows users to upload files when compiled to a Flash Version that
    uses ActionScript2 such as Flash 8
    -->
    <class name="fileuploadhelper" extends="node">

      <!---
      @param string uploadurl: (optional) default upload url to use if none
                               passed to this.upload()
      -->
      <attribute name="uploadurl" />

      <!--- @keywords private -->
      <!--- @param flash.net.FileReference file_reference: Flash file reference object -->
      <attribute name="file_reference" />

      <!-- *** METHODS *** -->

      <handler name="oninit" args="invoker">
        fr = new flash.net.FileReference();
        this.setAttribute('file_reference', fr);
        fr.addListener(invoker);
      </handler>

      <!-- *** METHODS *** -->

      <!---
      Displays file browsing window and allows the user to select a file (or
      cancel to close the window).
      -->
      <method name="browse">
        this.file_reference.browse();
      </method>

      <!---
      Return name of selected file

      @returns string: the filename of the selected file
      -->
      <method name="getName">
        return this.file_reference.name;
      </method>

      <!---
      Uploads the currently selected file.

      @param string strURL: (optional) If defined upload the file to this
                            URL, otherwise upload to this.uploadurl

                            Note: required if this.uploadurl is not defined.
      -->
      <method name="upload" args="strURL">

        if (strURL == null)
          var strURL = this.uploadurl;

        this.file_reference.upload(strURL);

      </method>


      <!-- * ABSTRACT HANDLERS * -->


      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when user selects a file.

      @param flash.events.Event ev: the select event
      -->
      <method name="onSelect" args="ev=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onSelect(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when progress event is captured.

      @param flash.net.fileReference fr: file_reference object here
      @param number bytesLoaded: the number of bytes of the file uploaded
      @param number bytesTotal: the number of total bytes of the file to be uploaded
      -->
      <method name="onProgress" args="fr, bytesLoaded, bytesTotal">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onProgress(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when a file upload is complete.

      @param flash.events.Event fr: the file_reference object
      -->
      <method name="onComplete" args="fr=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onComplete(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

      <!--- @keywords abstract -->
      <!---
      ABSTRACT METHOD: OVERRIDE IN YOUR APPLICATION TO DO SOMETHING USEFUL

      Called when the file upload fails.

      @param flash.events.Event fr: the file_reference object
      -->
      <method name="onError" args="fr=null">
        if ($debug) Debug.info('as3 (SWF9/10): fileuploadhelper.onError(): WARNING: This is an abstract method that should be overridden in your application to do something useful...');
      </method>

    </class>

  </when>

</switch>

</library>