Actionscript 3 FileReference load/save strings - actionscript-3

I am using file reference to prompt the user to save the file to a directory of their choice. The file extension for saving is a text-file, it has the string "Hello!" It does manage to save the file.
I am having trouble loading it and importing the string to stage so that the stage reads the instruction on the FileReference .txt file and goes to the page. For example, the string "Hello" should go to page = "Hello";
Please help? If someone can provide an example on what I'm doing wrong.

Related

How reading exif metadata from file

I'm trying to implement the following Exif reading library with as3, but I can't load the browsed file.
In the library example they use loader.load(new URLRequest("http://www.example.com/sample.jpg")); for loading the image, the problem in my application is that the file is selected by a file-browser in a local computer.
I tried a fileReference.name but it doesn't work, the only way that I found to make my test, is putting a file in the same directory than the .swf like this :
loader.load(new URLRequest("IMG_001.JPG"));
Can you tell me what is the parameter that I can put in the URLRequest function to get the path of the selected file ?
Thank you

Save text into txtfile using actionscript 3 without asking directory path from user

I am trying to save a string into .txt file using action script 3 ,I use this code :
var fileRef:FileReference;
fileRef = new FileReference();
fileRef.save("sasa", "saveFile.txt");
But this code asks the user the path location but i don't want to do it ,i need to save in the current directory of swf file without asking path from user?
Any ideas will be appreciated
I am so new in AS3
Best regards
I'm afraid you can't do that for security reasons. But if you're doign an AIR app you can use FileStream class

how to get browsed file location by user when he wants to download a file

this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.
You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).

turn folder into a zip file

I have a folder on my desktop and i want to convert it into a .zip file. It shouldnt ask me were to save it but just save it straight to my desktop or any folder i specified.
I tried ASZip, fZip etc. but i can't get it to work. There isn't any of them that seem to let me just add a folder and zip it.
I was only able to create a byteArray wit ASZip but when i saved it, it left me with a file that was not able to be opened.
Would it be possible to achieve what i want without the use of an external library?
Any help would be appreciated.
You can't actually zip a folder but you can zip all the contents inside the folder. You would have to use FileReferenceList to load in flash all the files inside the folder.
FileReferenceList allows you to have multiple selection in the browse window.
Then you would have to pass all these files to the zip managing library and get a ByteArray from it.
This byte array you would localy dump inside a "yourFileName.zip" by using FileReference.save().
The application cannot save the file to a predetermined location. The user has to pick the location using the "save to" prompt.

Is it possible to convert an XML file created in actionscript to a FileReference object?

I have a working s3 uploader in actionscript that uses the FileReference class so a user can browse for files to upload when he/she clicks on the upload button.
I have a web application and I want the user to have his/her configuration saved to s3 as an XML file when they hit the save button, so the "save" button will trigger the upload. However, i cant figure out a way to add the XML file to the FileReference variable I create. I was looking at the File class but that appears to be only usable in AIR.
Is it possible to create a FileReference object based off of an XML file that actionscript creates within the application without browsing for a file using FileReference.browse(); ?
Thanks
The answer to my original question is "no". According to this article by Mike Chambers, you cant.
It is apparently a sandbox issue so that a malicious flash program will not be able to do anything related to saving files without a users permission.