fingerprint211b
fingerprint211b

Reputation: 1186

Saving an image as a file on the client side?

I'm rather inexperienced with flash and as3, and I've been given a task of writing a program that downloads images from URLs that are provided, and saves them to a specified location on the user's computer.

The idea is to be able to download multiple images (user selects them) and download them all to a single directory (which the user selects first) so that he doesn't have to download them one by one. Also, putting them in an archive and downloading as one file wasn't an option.

The only solution I found is using FileReference.save(), which won't work for me because it opens a save dialog.

If this is impossible to do in flash, please suggest another way of doing this without resorting to installing custom plugins.

Thank you.

Upvotes: 0

Views: 294

Answers (1)

epologee
epologee

Reputation: 11319

The biggest issue you're going to run into is the flash player sandbox security. By design, it is not possible to mix file requests from your local computer with file requests on a network, if your SWF is already on the network. The reason for this is to prevent malicious SWF's to send files from your computer to the internet. It took me a while to fully understand the security restrictions, but it's all here, in the Adobe AS3 help docs.

At the bottom of that page, you'll see the list of security sandbox types, and if you're creating a website (REMOTE), you're not going to achieve your design in Flash without resorting to funky 3rdparty browser plugins:

  • Security.REMOTE
  • Security.LOCAL_WITH_FILE
  • Security.LOCAL_WITH_NETWORK
  • Security.LOCAL_TRUSTED ← can do what you need.
  • Security.APPLICATION ← can also do what you need.

The LOCAL_* sandboxes all deal with SWF's that are on your computer, but for them to access both other files on your computer and then send them to the network, the user needs to manually 'trust' the SWF. Assuming you're creating your app for a broader public, this is probably not a viable option.

Your best bet would be to go with AIR. As specified in APPLICATION, you can mix local and network resources. Your users will however need administrator rights on their computers and trust you enough before they can install your app as an AIR desktop application.

Good luck! EP.

Upvotes: 3

Related Questions