Image Upload progress using URLLoader AS3
Asked Answered
P

2

8

I am developing image uploader in Flash. I use FileReference.browse to browse image then resize this image to 1000 x 1000 px, if the image is very big and then upload to server. I want to show progressbar for the image upload progress.

I am usinng URLLoader to send binary data of the resized images, but ProgressEvent on URLLoader doesn't work the way it is supposed to work. It is fired only after the image is completed uploaded instead of showing intermediate progress. ProgressEvent on FileReference works perfectly to show intermediate image upload progress.

Is there a way to display upload progress using URLLoader? or

Can we use FileReference to load modified image and then call FileReference.upload, that way it will be possible to show actual progress bar.


Update 1 :
But my problem is that I am resizing the browsed image after using FileReference.browse, and I want to upload resized images, not the original picture in FileReference object after browse. How do I use Filereference.upload in this case? Filereference.upload will upload original image not the resized one. Any idea, how to put the resized image into Filereference object and then use FileReference.upload.


Update 2 :
Not able to set data in dummy FileReference, data is read-only property.


Update 3 :
But this has same problem of not showing image upload progress, from the above link:

"Unfortunately there is a problem getting progress event. We cant show any progress during sending data to server because flash doesn't support it"

I am exactly looking for a solution for the above issue. URLLoader works fine to post the image data.

Pea answered 2/10, 2009 at 22:57 Comment(4)
I'm doing the EXACT same thing and stumbled on the same problem. I'm thinking of putting a "imprecise loading bar" while the upload is in progress.Porcine
Given that in my case the resulting file usually has about the same size, I ended setting up a Timer with the estimated time the upload should take in most situations, and getting that timer to fire ProgressEvents for the progressbar to update. It's better than nothing and the users can't tell the difference.Porcine
Now thats what i call a 'brillant solution'.Antisepticize
It's clever but it's completely inaccurate. 'In most situations' doesn't mean anything. I'd rather use an indeterminate progress bar instead of lying to the user.Stamford
P
3

URLLoader is setup in such a way that it CANNOT receive progress events until the load is complete, as noted HERE in the docs. You might be able to use URLStream instead to get the progress event as you desire perhaps? I'm not sure if the progress events for URLStream only fire for download of the server's reponse, or if they will fire for the full transaction (upload & download), the docs don't seem to specify precisely.

Pleura answered 8/12, 2010 at 20:14 Comment(2)
This has been upvoted twice... I wonder if anyone has tried it and confirmed if URLStream dispatches proper progress events? I've read elsewhere that it doesn't, but so far no definitive source... Oh well.Nettle
I don't see anything in URLStream that would suggest it can be used for uploading anything at all! The documentation describes DOWNloading in detail, but there isn't even an upload method. Could you specify how you would use it to upload a file?Tymothy
P
-1

Use FileReference.upload, that's specifically what that method is for, and you will have your progress indicator.

Pleura answered 3/10, 2009 at 19:31 Comment(2)
He is not trying to upload the original file, but the ByteArray of the JPEG encoding of the resulting resize of the original file.Porcine
Hmm, could have sworn that the original question did not mention that... oh well, I've reposted a new answer that applies to the situation as currently represented.Pleura

© 2022 - 2024 — McMap. All rights reserved.