0

I need to test the upload speed of the client machine in AS 3.0. So I thought to upload an image that embed to swf, to server without user interaction. Do you have idea about how to do this?

Rukshan Dangalla
  • 2,500
  • 2
  • 24
  • 29

2 Answers2

1

The easiest way would be to send any data as binary in post request. Uploading, however, is a different thing, because it also requires IO on the server side.

It's not clear what are your options and / ore requirements server-side. Does it have to mimic HTML form behavior (i.e. does it have to send multipart-form data headers?) or can you just go with content-type: application/octet-stream? This is different because first can only be done through FileReference, or would require you to patch the server as to send policy files in response to a specific requests + implement HTTP protocol on your own using sockets. While sending plain binary data (the second option) is easier to implement and has fewer restrictions, however, you would need to manage IO required on the server for saving uploaded data on your own.

Note that testing FileReference behavior automatically is not possible because it requires users to click, and it will only send data in response to click events.

  • Thanks for you response. I found a way to do this. – Rukshan Dangalla Feb 26 '12 at 14:57
  • First I convert embed image to byte array according to this, [convert-embed-image-to-bytearray](http://flexbuilderblog.wordpress.com/2010/01/25/convert-embed-image-to-bytearray/) And then,I send that byte array to server, according to this(with modification), [upload-bitmapdata-snapshot-to-server-in-as3](http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/) And measure the time it will take. – Rukshan Dangalla Feb 26 '12 at 15:14
0

Hi I found the best way to do this with out image. First I created a byte array,

private var _byteArray:ByteArray = new ByteArray();
for(var i:int = 0; i < 200 * 1024;i++)
{
  _byteArray.writeByte(1);
}

And send that 200KB bytearray to server using urlloader and urlrequest

uploadURL = new URLRequest();
uploadURL.url = "upload.php";
uploadURL.contentType = 'application/octet-stream';
uploadURL.method = URLRequestMethod.POST;
uploadURL.data = _byteArray;
urlLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.load(uploadURL);

protected function completeHandler(event:Event):void
{
   trace("Upload Complete");
}
Rukshan Dangalla
  • 2,500
  • 2
  • 24
  • 29