Flex - Download asset to local - apache-flex

I've got an interactive presentation, and it's all working as it should.
Now I want to add a function to download the currently visible image/video.
Because this presentation has a lot of files (all stored under assets/...) and it's a pain to navigate through the assets, I want an easy way to just click a button and get a "Save as.." window.
I've managed to get the url of the media, so now I just need a way to show a "save as.." dialog to allow the users to save/download the file and save it locally.
This whole presentation should be put online, so all the files are located somewhere in the /assets/.. folder inside the project.
Any ideas of how to do this? =)
Thanks!
EDIT #1:
For now I'm using "navigateToURL" to open a new browser window with the media. This works, but is there a way to show a "Save as.." dialog instead of opening the image?
Or any other ways to do this? =)

You are looking for the FileReference class, in particular the FileReference.save( data:*,defaultFileName:String = null ) method. That will open up a "Save..." dialog to save the corresponding data object and allow you to set a default file name. I'm unsure if this class can also handle the download as I have never had a time when I needed to prompt to save something that was to be downloaded. If it cannot handle it, you'll need to look into the URLStream class. That can handle the download and either on ProgressEvent.PROGRESS or Event.COMPLETE, you simply do a URLStream.readBytes( byteArray ); to save the downloaded bytes to a ByteArray and then that is the data object you save. I would look into the FileReference class, though. Odds are it can handle downloads as well.

Related

How to change working directory via extension in Adobe brackets

Given a file or path - I can use FileUtils (or similar) to work with files. I'd like to be able to alter the current working directory in my extension.
I see in node.js there is process.chdir(directory) but I am unable to access that object.
Is there any other way to change the current working directory.
I am trying to create a simple plugin that when you open the file dialog, the directory your file listing is the same as the currently opened file. The simple implementation being:
MainViewManager.on("currentFileChange", function (e, newFile) {
process.chdir(newFile.parentPath); // This is my FAIL
});
Brackets, like many GUI apps, doesn't use the current working directory very much once it's up and running. So there is probably a different way to accomplish what you're looking for.
When you say...
when you open the file dialog, the directory your file listing is the same as the currently opened file.
...do you mean you want the file tree on the left side of the window to change? If so, try the ProjectManager.openProject() API.
...or do you mean you want to open a file-picker dialog box (like what you see when you choose File > Open in the menu)? If so, you can use FileSystem.showOpenDialog() - the 4th argument is the directory to show when the dialog is first opened.

Possilble to auto open a downloaded word document downloaded in browser

The requirement is sent a Word document from browser, and automatically open it on MS Word so that then can view and edit the Word document.
The only solution I can found require the end user to click a dialogue Window in order to open a Word document in Office when the document is download from browser.
Is this the only way, that the user has to click a dialogue Window before Office can open the downloaded Word document?
It kinds of make sense for security reason to not let browser automatically execute an local application (Word.exe) on the local machine, but I still want to confirm that.
If the answer is yes, then I would like to know how to do that?
Edit: I just found out that you have to use inline instead of Attachement, otherwise it will always ask for the option event the browsers are setup properly.
Response.AddHeader("Content-Disposition", "inline;filename=clientquotes.docx");
After made that change, browser will auto open the Word document without asking for action.
If I understand correctly, you want to change the behaviour of your browser to automatically open downloaded files. As far I'm aware its pretty painless process when it comes to Firefox and Google Chrome, however on IE it's not as simple.
Firefox
Changing download actions
This will not affect media embedded in a web page - only links to the files themselves.
Click the menu button Menu and choose Options
Select the Applications panel.
The Applications panel will display. Select the type of file for which you want to change the default action.
The Action column will give you a drop-down menu, with options on action to take, whenever you click that type of file.
Alwaysask: will prompt you to select what action you want Firefox to take when you click on that type of file. This can be useful if Firefox is automatically saving a file type or is always opening it with a certain program and you want to be asked what to do.
Save File: will always save the file to your computer using the Downloads window, whenever you click that type of file.
Open the file with an application or plugin of your choosing.
Click Ok to close the options window after making changes
Adding download actions
On the web, find a link to a file matching the type you want to add.
Click on the file link to download it.
Select how you want Firefox to handle the file:
Open with: Saves the file to a temporary folder and opens it in the default application for that file type. To select an application, click Browse....
Do not choose Firefox to always open a certain file type, as doing so can cause
a problem where Firefox repeatedly opens empty tabs or windows after you click on a link.
Save file: Saves the file to the download folder (specified in the Firefox General panel).
In the Opening file window, check mark Do this automatically for files like this from now on.
Click Ok.
Is Do this automatically for files like this from now on disabled?
This can happen if the website's server incorrectly specifies the
Internet Media type of the file. It also can happen if the server assigns
"Content-Disposition: attachment" to the file.
Reference
Google Chrome
If you want certain types of file always to open after they've finished downloading, click the arrow next to the file button in the downloads bar and select Always open files of this type.
Reference
IE
From what I can gather for IE you will have to change the registry keys. You can refer to this link for further information.
I hope this answers your question.

How can I continue using a web app while a file uploads from 1st screen?

I have a project that needs to upload a large file, while that file is uploading is it possible to progress through a series of other screens, to continue to obtain input from user, then once they get to the final screen, file is uploaded.
Anyone have a trick for something like this ? As i know the file upload happens within a form post/get.
You can do this using an iframe, which simple links to a page with a form to post a file, once the user has selected a file and clicked upload/submit you can hide the iframe and progress into our areas... but things will get tricky where you need to handle errors, ie: incorrect file formats, zero byte files etc... maybe you can download the file and display any errors right at the end of your process/wizard input.

How do I rotate an Image in .NET?

I have an asp.net 2010 project. I write a jpg to the filesystem. Then I display it in an Image control. Then I use this code on button click to allow the user to rotate it 90 degrees.
string path = Server.MapPath(Image1.ImageUrl) ;
// creating image from the image url
System.Drawing.Image i = System.Drawing.Image.FromFile(path);
// rotate Image 90' Degree
i.RotateFlip(RotateFlipType.Rotate90FlipXY);
// save it to its actual path
i.Save(path);
// release Image File
i.Dispose();
It does rotate (I can actually watch that happen in Windows Explorer). But when I run the app again and it grabs the file from its path, it still displays it in its original form.
Try adding a dummy querystring to the end of the image like "image1.jpv?v=1". This works to prevent caching for things like Javascript files and it may do the same for you.
This is the classic issue with browser-cached resource files. Alison's answer is one option. Another option is to change the name of the physical file. If you "version" the files, then after each change, the file name will be different. This does mean that you'll have to dynamically reference the image path so that you display the correct version, and you'll need some way to determine the file name for the current version. It does prevent the browser from displaying the previously cached file immediately after a change, though, because it's technically a new file to the browser at that point.
If you are using some sort of data source (XML files or database) to store metadata for the images, then you can add a "Version" column and store a simple integer. With each change, increment the integer value and use the new value in the file name. You can even extend this by saving the previous versions and allowing your users to "undo" actions by copying an older version of the file into a new version. This might require a more robust metadata storage implementation, though.

Losing extension when use FileReference download

I need user download JPEG file from my app, however, when user change the file name the saved file will be downloaded without extension.
For Example: I am using FileReference.download() and set the default filename as "demoPic.jpg" and user's windows system setting control file extension not being shown. So when the dialog opens a download window, only "demoPic" shown as the filename. If user saved file without changing filename, the saved file will be OK. But if user change file name, the download file will be saved without extension. is it possible to add file extension to filename when user forget it by flex code?
This is a known problem with Flash Player. An enhancement request is filed with Adobe. Please visit and vote for it: https://bugs.adobe.com/jira/browse/FP-2014
It does not seem practical to train users not to rename the file. Here is the workaround I use for my app:
The problem only happens on Windows with ActiveX plugin. Detect ActiveX with Capabilities.playerType (only ~25% of users in my experience)
If ActiveX plugin, fall back to 'navigateToURL()' to bounce the file on your server. Using this function is less desirable than FileReference.download() because it is less controllable (the browser is in charge, rather than your app), but it results in a Save dialog box where the user can rename the file safely.
I have the same problem and was not able to fix it until now. It seems it is a problem with flash + windows. :( sorry to inform but I did not found any fix.
If this can be called a workaround, is somehow to warn users and ask them to place also the extension when they rename the file.
Had same problem. Used CONCAT to manually add extension. It does not appear in the dialog box when saving but DOES save as a text file with a .txt extension when viewed in Windows Explorer. Doesn't seem to work but actually does!
var final_filename:String = filename.concat(".txt");
//Create text to save from text field
var newDataFile:TextField = new TextField();
newDataFile.text=myTextField.text;
//create file reference to save file
var file:FileReference = new FileReference();
file.save(newDataFile.text, final_filename);
you just need to use navigateToUrl(ur)
var ur:URLRequest=new URLRequest();
var fr:FileReference=new FileReference();
fr.download(ur,<FILENAME>);
"download" method call fileBrowser and then call servlet .
then flex can't catch file extension
but "navigateToUrl" called servlet first then servlet call fileBrowser
then html can catch file extension

Resources