Question

It would appear that FileReference.upload() is the only way in which you can upload a file to the server in Flash and get feedback about its upload state via a PROGRESS callback. All other methods just go off into the ether and come back when the file upload is completed.

Unfortunately, FileReference appears to insist that a user select the file to be uploaded. There doesn't appear to be a mechanism by which to set the file through code. The reason I need this is that I'm allowing the user to upload massive files and am uploading them in chunks, so, I want to just pack a chunk of data into a FileReference (maybe 5 or 10 megs) and send that off and watch it go. Does anyone have any thoughts on whether it's possible to manually load data into a FileReference object? The data property is read-only, sadly. Any and all advice on this will be treated with kindness :)

Was it helpful?

Solution

The poster is not trying to upload random files from a users system, but rather trying to get file reference to upload custom data - which it unfortunately can't.

I found this link to be very helpful: http://labs.findsubstance.com/2008/04/03/as3-upload-encode-images/

OTHER TIPS

Yes, that shouldn't be possible, it's a security measure. I.e. you shouldn't be able to send random files from user's PC without users explicitly selecting them to be sent.

However, you can monitor the upload, if you design it differently. For instance, you could use URLStream or Socket or NetConnection to send any data you want and to configure the server to respond in a way you need. For example, URLStream provides a read/write stream that you can use for both sending and receiving the data. You could then use it with some sort of a buffer: send the content of the buffer, wait for the server to acknowledge the data was received, refill the buffer, repeat.

EDIT: So I'm guessing we are talking about AIR application (since you mention File)? So, you are probably opening a file using FileStream and wanting to send a chunk of data you just received by using FileReference.upload() - is that correct? Well, then it seems like FileReference cannot do it silently. Still, I would use URLStream to split the big chunk of data you want to upload into, say 100 parts and then send each part after receiving OK from the server script configured to accept it. Usually, file upload is handled directly by the HTTP server, but your case will require some extra work, namely, launching a script that would negotiate "package" size, receive the packages and acknowledge the reception. This may be less trivial for server scripts that might time out, but there certainly must be a solution to this.

Alternatively, you could configure your HTTP server to serve socket policy once it receives a socket policy request, afterwards, you could connect with the Socket and just copy the multipart-form-data kind of request usually sent through FileReference or similar HTML control. (I'd probably choose this way, if it wasn't a shared hosting or anything else that would prevent me from being able to configure the server).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top