How the save the file without promting the dialog box in flex. Options

21 views
Skip to first unread message

Lokh Prathab

unread,
Sep 4, 2009, 9:14:59 AM9/4/09
to Adobe Developers of Greater Orlando
Hi All,

We are using flex 3.3 and flash player 10. I got the information from
the google where I can save the file using FileReference.save method.
However, this method opens a dialog box and ask for selecting the
directory where you want to save the file.
We want to save the file to the default location say C:\abc
\myimapge.jpeg also I do not want to show the dialog box which
appears
on the save method. Does anybody encounter this problem?
How to avoid the dialog box which appearing while saving the image?


Just for refernce see following example where the graph is saved to
the selected location through the dialog box.


http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-th...


If you click on save button, it opens a window asking for selecting
the path.


I want to avoid above step. It should save the file to some
predefined
location without showing dialog box.

Maxim Porges

unread,
Sep 4, 2009, 10:31:20 AM9/4/09
to ad...@googlegroups.com
This is not possible with Flash. The Flash Player sandbox requires
that the dialog box be opened to warn the user that your app is trying
to save a file to their computer.

If you can use an AIR app instead, you should be able to do direct
file system manipulation without prompting the user.

- max

Lokh Prathab

unread,
Sep 4, 2009, 10:49:03 AM9/4/09
to Adobe Developers of Greater Orlando
Hi Maxim,

Thanks for reply. Am using AIR application only, Let me know
briefly to fix this issue. And use this link sample:
http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-using-the-filereference-class/

for coding reference



Thanks in Advance

Lokh
> > location without showing dialog box.- Hide quoted text -
>
> - Show quoted text -

Maxim Porges

unread,
Sep 4, 2009, 12:13:44 PM9/4/09
to ad...@googlegroups.com
Just look at the AIR documentation on the File class and its peers.

- max

Lokh Prathab

unread,
Sep 9, 2009, 5:09:59 AM9/9/09
to Adobe Developers of Greater Orlando
Hi Folks,

I fixed this issue by using urlstream class in flex,



On Sep 4, 9:13 pm, Maxim Porges <maxim.por...@gmail.com> wrote:
> Just look at the AIR documentation on the File class and its peers.
>
> - max
>
> On Sep 4, 2009, at 10:49 AM, Lokh Prathab wrote:
>
>
>
>
>
> > Hi Maxim,
>
> >        Thanks for reply. Am using AIR application only, Let me know
> > briefly to fix this issue. And use this link sample:
> >http://blog.flexexamples.com/2007/07/28/downloading-files-in-flex-usi...
> >> - Show quoted text -- Hide quoted text -

Maxim Porges

unread,
Sep 9, 2009, 11:13:34 AM9/9/09
to ad...@googlegroups.com
That helped you get around the file dialog and you were still able to
write a file to the user's system from Flash? How did you do that?

- max

Lokh Prathab

unread,
Sep 10, 2009, 1:23:04 AM9/10/09
to Adobe Developers of Greater Orlando
HI Maxim,

Yes you right, By streaming the bytes from url and we need to
write into a file using filestream, Please refer the code below:

-----------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">

<mx:Style>
.progressWindow
{
background-color:#FFFFFF;
border-style:solid;
drop-shadow-enabled:true;
corner-radius:5;
}

.progressStyle
{
vertical-center:0;
horizontal-center:0;
}
</mx:Style>

<mx:Script>
<![CDATA[


import flash.filesystem.*;
import com.ProgressWindow;

public var stream:URLStream = new URLStream();
public var file:File = File.documentsDirectory.resolvePath("c:/
jackson.mp4");
public var fileStream:FileStream = new FileStream();

public function init():void
{
stream.addEventListener(ProgressEvent.PROGRESS, progressBar);
stream.addEventListener(Event.COMPLETE, writeComplete);
stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
stream.addEventListener(Event.OPEN, opentHandler);

stream.load(new URLRequest("http://localhost:8080/concept/
jackson.mp4"));

}

public function writeComplete(evt:Event):void
{
var fileData:ByteArray = new ByteArray();
stream.readBytes(fileData,0,stream.bytesAvailable);
fileStream.openAsync(file, FileMode.UPDATE);
fileStream.writeBytes(fileData,0,fileData.length);
fileStream.close();
stream.removeEventListener(ProgressEvent.PROGRESS, progressBar);
stream.removeEventListener(Event.COMPLETE, writeComplete);
ProgressWindow.getInstance().close();

}

public function progressBar(event:ProgressEvent):void
{
ProgressWindow.getInstance().setProgress
(event.bytesLoaded,event.bytesTotal);
}

private function ioErrorHandler(event:IOErrorEvent):void
{
ProgressWindow.getInstance().close();
}

private function securityErrorHandler
(event:SecurityErrorEvent):void
{
ProgressWindow.getInstance().close();
}

private function opentHandler(event:Event):void
{
ProgressWindow.getInstance().show();
}

]]>
</mx:Script>


</mx:WindowedApplication>

-----------------------------------------

Lokh
Reply all
Reply to author
Forward
0 new messages