Hi all,
I am starting to tear my hair out because of a problem I have with the URLLoader class, så hope that one of you might be able to help
I have a Flash application where the user can upload a picture, modify and when clicking save I use the BitmapData.draw to capture the new picture, which I then encode as a png and send to php on my server.
99% of the time it works perfectly, but sometimes it fails - more specifically it fails about 5% of the time on a Mac using Safari (it always work on the Mac using Firefox, and the problem doesn’t appear when using Windows XP, no matter which browser is used).
What seems to happen is, that the URLLoader newer actually sends the request.
I monitor ALL events, including Http, IOError, Complete etc. and nothing seems to happen after I call URLLoader.load().
The URLLoader variable is placed outside the function calling it, so it shouldn’t be garbage collection.
When it fails, I can see in my server-log, that no call was made to the server, and using the Activity monitor in Safari is looks as if the call was made, but that no bytes where send.
Here is my code:
var pngSource:BitmapData = new BitmapData (areaWidth, areaHeight);
pngSource.draw(pictureComposer);
var pngStream:ByteArray = PNGEncoder.encode(pngSource);
var filename:String = "myfile";
var encoded:String = Base64.encodeByteArray(pngStream);
var variables:URLVariables = new URLVariables();
variables.png64 = encoded;
var pngURLRequest:URLRequest = new URLRequest("http://www.myurl.com/save_picture.php?name=" + filename);
pngURLRequest.method = URLRequestMethod.POST;
pngURLRequest.data = variables;
_loader = new URLLoader();
_loader.addEventListener(ProgressEvent.PROGRESS, loaderProgress);
_loader.addEventListener(Event.COMPLETE, loaderComplete);
_loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
_loader.addEventListener(Event.OPEN, onOpen);
_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHttp);
_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurity);
_loader.load(pngURLRequest);
The above version encodes the png using base64 and sends it as a string, but I have also tried using the application/octet-stream header and sending is as a binary-stream, with the exact same problem.
Hope that one of you guys has a clue what happens, because I surely don’t :hurt:
Thanks in advance,
Mads