This is for open a file from file system.
My goal is to open a file on the file system from a byte array that exists
on the application, so I download the file and the user needs to press it
(right now not it's the way to go).

However I will also need your feature soon, so thank you.
It will be very ususfull and one less issue to solve.

Maria Jose Esteve <mjest...@iest.com> escreveu no dia terça, 15/09/2020
à(s) 10:08:

> Hi Hugo, sorry for the delay.
>
> Here you can see how we work with mx.net.FileReference. (I have adapted
> the code to be able to show it to you in a few lines, there may be omission
> or transcription errors)
>
>     import org.apache.royale.events.Event;
>     import org.apache.royale.events.IEventDispatcher;
>     import mx.net.FileReference;
>     import mx.net.FileFilter;
>     import mx.events.IOErrorEvent;
>     import mx.events.SecurityErrorEvent;
>     import mx.utils.ByteArray;
>
>         public var allowedExtensions:String =
> '*.jpg;*.jpeg;*.gif;*.png;*.bmp';
>         public var maxFileSize:Number = 2;
>         public var fileType:String;
>         public var fileName:String;
>         private var fileData:ByteArray;
>
>         public function loadFromFileSystem():void
>         {
>                 fileData = null;
>                 fileType = "";
>                 fileName = "";
>
>                 var file:FileReference = new FileReference();
>                 file.addEventListener("cancel", cancelHandler);
>                 file.addEventListener(Event.SELECT, selectHandler);
>                 file.browse([new FileFilter('Image',allowedExtensions)]);
>         }
>
>         private function cancelHandler(event:Event):void
>         {
>                 var dispatcher:IEventDispatcher =
> IEventDispatcher(event.target);
>                 dispatcher.removeEventListener("cancel", cancelHandler);
>                 dispatcher.removeEventListener(Event.SELECT,
> selectHandler);
>         }
>
>         private function selectHandler(event:Event):void
>         {
>                 var file:FileReference = FileReference(event.target);
>                 file.removeEventListener("cancel", cancelHandler);
>                 file.removeEventListener(Event.SELECT, selectHandler);
>
>                 var fileTypeIndex:int = file.name.search(new
> RegExp("\.[^\.]+$"));
>                 var _fileType:String = fileTypeIndex >= 0 ?
> file.name.slice(fileTypeIndex).toLowerCase() : "";
>
>                 if (allowedExtensions.search(_fileType.toLowerCase()) ==
> -1) {
>                         Alert.show(String("File type not supported") + "
> (" + allowedExtensions.replace(/\*\./g, "").replace(/;/g,
> ",").toUpperCase() + ")");
>                         return;
>                 }
>                 if (!isNaN(maxFileSize) && file.size > maxFileSize * 1024)
> {
>                         Alert.show(String("Maximum file size exceeded") +
> " (" + maxFileSize + " KB)");
>                         return;
>                 }
>
>                 file.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
>                 file.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
> errorHandler);
>                 file.addEventListener(Event.COMPLETE, completeHandler);
>                 fileType = _fileType;
>                 fileName = file.name;
>
>                 file.load();
>         }
>
>         private function completeHandler(event:Event):void
>         {
>                 var dispatcher:IEventDispatcher =
> IEventDispatcher(event.target);
>                 dispatcher.removeEventListener(IOErrorEvent.IO_ERROR,
> errorHandler);
>
> dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,
> errorHandler);
>                 dispatcher.removeEventListener(Event.COMPLETE,
> completeHandler);
>
>                 fileData = Object(dispatcher).data;
>         }
>
>         private function errorHandler(event:Event):void
>         {
>                 var dispatcher:IEventDispatcher =
> IEventDispatcher(event.target);
>                 dispatcher.removeEventListener(IOErrorEvent.IO_ERROR,
> errorHandler);
>
> dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,
> errorHandler);
>                 dispatcher.removeEventListener(Event.COMPLETE,
> completeHandler);
>
>                 fileData = null;
>         }
>
> In the view, you can have a Jewel BinaryImage that you will assign
> fileData to:
>
>         //xmlns:j="library://ns.apache.org/royale/jewel"
>         <j:BinaryImage binary="{fileData}"  height="117" width="117"
> click="loadFromFileSystem()" />
>
> I don't know if this will help you ... (An example of this type is never
> bad, right?)
>
> Hiedra.
> -----Mensaje original-----
> De: Carlos Rovira <carlosrov...@apache.org>
> Enviado el: lunes, 14 de septiembre de 2020 10:22
> Para: Apache Royale Development <dev@royale.apache.org>
> Asunto: Re: Open ByteArray as file
>
> Hi Hugo,
>
> sure, don't worry I'm sure others will take a look soon.
> thanks
>
> El dom., 13 sept. 2020 a las 18:06, Hugo Ferreira (<hferreira...@gmail.com
> >)
> escribió:
>
> > OK.
> > For now, I'm using my own implementation.
> > If in a near future my fix is integrated in Royale framework, I will
> > delete my implementation on use directly from Royle.
> >
> > Carlos Rovira <carlosrov...@apache.org> escreveu no dia domingo,
> > 13/09/2020
> > à(s) 15:52:
> >
> > > Hi Hugo,
> > > since I don't have much use of that class hope others can review it
> > > thanks
> > >
> > > El dom., 13 sept. 2020 a las 2:59, Hugo Ferreira (<
> > hferreira...@gmail.com
> > > >)
> > > escribió:
> > >
> > > > FileReference fixed with a PR.
> > > > My only issue is that I assumed PDF as default file type but one
> > > > should gave a name any way or make the fileName mandatory.
> > > >
> > > > Hugo Ferreira <hferreira...@gmail.com> escreveu no dia sexta,
> > 11/09/2020
> > > > à(s) 14:54:
> > > >
> > > > > Hi Maria,
> > > > >
> > > > > Of course.
> > > > > At the moment I can download a ByteArray that came from the
> > > > > server, without violating any of the browser rules.
> > > > > If I could open the file, it would be great.
> > > > >
> > > > > Maria Jose Esteve <mjest...@iest.com> escreveu no dia sexta,
> > > 11/09/2020
> > > > > à(s) 14:45:
> > > > >
> > > > >> Hello Hugo,
> > > > >> I don't know if this will help you ...
> > > > >>
> > > > >> I could send you an example of "image opening" with from
> > FileReference
> > > > >> and its transfer to the backend as ByteArray by AMF3 ... Would
> > > > >> it be
> > > > useful?
> > > > >>
> > > > >> Hiedra
> > > > >>
> > > > >> -----Mensaje original-----
> > > > >> De: Hugo Ferreira <hferreira...@gmail.com> Enviado el: jueves,
> > > > >> 10 de septiembre de 2020 13:32
> > > > >> Para: Apache Royale Development <dev@royale.apache.org>
> > > > >> Asunto: Re: Open ByteArray as file
> > > > >>
> > > > >> On my case I have a ByteArray returned from a AMF call to the
> > server,
> > > so
> > > > >> it's not UI/MXML.
> > > > >> On my Flex/AIR application I convert this ByteArray on a
> > > > >> temporary
> > > file
> > > > >> and open it.
> > > > >> Here I want to do the same (if I can avoid to create a
> > > > >> temporary
> > file
> > > on
> > > > >> the middle, would be a better way).
> > > > >> A AS util function that I can reuse and encapsulates the JS
> > > > >> code,
> > > > perhaps
> > > > >> the best approach ?
> > > > >>
> > > > >> Carlos Rovira <carlosrov...@apache.org> escreveu no dia quinta,
> > > > >> 10/09/2020
> > > > >> à(s) 11:12:
> > > > >>
> > > > >> > Hi,
> > > > >> >
> > > > >> > Since Royale is about encapsulating code that works through
> > > platforms
> > > > >> > (and in JS cross browser), I think it would be good to have a
> > > > >> > bead
> > > for
> > > > >> > that at Core or Basic level.
> > > > >> >
> > > > >> > just my 2...
> > > > >> >
> > > > >> > El jue., 10 sept. 2020 a las 11:45, Harbs
> > > > >> > (<harbs.li...@gmail.com
> > >)
> > > > >> > escribió:
> > > > >> >
> > > > >> > > There is also a FileReference implementation in the mx
> package.
> > > > >> > > mx has a DownloadButton which does what you want.
> > > > >> > >
> > > > >> > > You also might want to know about URLUtils.
> > > > >> > >
> > > > >> > > HTH,
> > > > >> > > Harbs
> > > > >> > >
> > > > >> > > > On Sep 10, 2020, at 12:33 PM, Hugo Ferreira
> > > > >> > > > <hferreira...@gmail.com>
> > > > >> > > wrote:
> > > > >> > > >
> > > > >> > > > Sometimes it easy to forget that Royale at the end of the
> > > > >> > > > day
> > IS
> > > > >> > > > JS :)
> > > > >> > > >
> > > > >> > > > Piotr Zarzycki <piotrzarzyck...@gmail.com> escreveu no
> > > > >> > > > dia
> > > > quinta,
> > > > >> > > > 10/09/2020 à(s) 05:53:
> > > > >> > > >
> > > > >> > > >> Hi Hugo,
> > > > >> > > >>
> > > > >> > > >> I will just shot you with the tip - How would you do
> > > > >> > > >> that in
> > > pure
> > > > >> JS ?
> > > > >> > > - I
> > > > >> > > >> think this maybe your answer ;)
> > > > >> > > >>
> > > > >> > > >> Thanks,
> > > > >> > > >> Piotr
> > > > >> > > >>
> > > > >> > > >> czw., 10 wrz 2020 o 01:59 Hugo Ferreira <
> > > hferreira...@gmail.com>
> > > > >> > > >> napisał(a):
> > > > >> > > >>
> > > > >> > > >>> I have a ByteArray to comes from the server side.
> > > > >> > > >>> I would like to open now the file.
> > > > >> > > >>> With Flex (AIR), I use FileStream.
> > > > >> > > >>> What's the equivalent here.
> > > > >> > > >>> I would like to open the file.
> > > > >> > > >>> If not possible (for security reasons since we are on
> > > > >> > > >>> web space), at
> > > > >> > > >> least
> > > > >> > > >>> download the file, so the user can click on it.
> > > > >> > > >>>
> > > > >> > > >>> What is the Royale approach/code, for that ?
> > > > >> > > >>>
> > > > >> > > >>
> > > > >> > > >>
> > > > >> > > >> --
> > > > >> > > >>
> > > > >> > > >> Piotr Zarzycki
> > > > >> > > >>
> > > > >> > >
> > > > >> > >
> > > > >> >
> > > > >> > --
> > > > >> > Carlos Rovira
> > > > >> > http://about.me/carlosrovira
> > > > >> >
> > > > >>
> > > > >
> > > >
> > >
> > >
> > > --
> > > Carlos Rovira
> > > http://about.me/carlosrovira
> > >
> >
>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>

Reply via email to