I am just getting started using Flash Builder 4.5 / Flex sdk. I was hoping someone might be able to give me a generic way to create the following:
I need a Flex or Action Script 3 component that will let users upload a single image and allow them to preview the image, name it and save it to my server. It should be 200px x 200px max dimensions. There should be a text input box where they enter the name, and two buttons; "Browse" and "Save", where browse lets them look through their local hard drive for an image to upload and "Save" sends the image to the server. Finally, there should be an alert saying the upload has completed.
so you need user interface with main features: "select" (local file), "preview" and "upload". I think that article fits nicely your requirements:
("Previewing an image before uploading it using the FileReference class in Flash Player 10")
So you first use FileReference local "load" feature and then simply use URLRequest to send binary data to your server (when user opts for that of course). The data from FileReference "load" is raw binary image data that you then need to upload to your server. This could be tricky and depends on server consiguration, script, etc. For some discussion see e.g.:
(sample wrapper class for URLRequest expects that you provide filename and byteArray - both available in file reference instance after load operation completes).
The "POST" operation needs to be started on user MouseEvent.CLICK handler for "upload" button (or any other similar user interface part that reacts to user action) due to security restrictions in Flash runtime (unless you're targeting Air runtime). So in web browser you need to start routine that creates URLReqest upload within block that handles user action:
(URLLoader data format needs to be URLLoaderDataFormat.BINARY)