How to upload a BitmapData Object straight to my server?


I wish to upload from my Flash Application (AS3) to imageshacks XML API. I wish to know how I can do this.

"In Flash, we must POST the data using the UrlRequest and UrlLoader classes, however we run into a limitation of the Flash API. The data property of a UrlRequest can either be a UrlVariablesByteArray object. There is no easy way to send name value pairs along with the JPG byte array. This is a big problem, because most upload applications will require a filename and other headers to accompany the raw file data"

I was hoping if someone could help me overcome the above!

Thanks all


I have tried making use of this tutorial here:

The problem is it's not for unsaved images, but it get images from your local machine and then uploads it to the server where the images has had a name already!

4/20/2009 11:45:21 AM

Accepted Answer

This was of great help to me:

You need to modify the URLRequestWrapper to insert field names and file names where needed. Here's what I've done:

bytes = 'Content-Disposition: form-data; name="' + $fieldName + '"; filename="';

It does the most formatting of headers so the server could understand it as a file upload.

By the way, if you have a BitmapData you might need to encode it to JPEG or PNG first.

Regards, Artem

9/18/2015 5:21:10 PM

You can send your filename data and any other data you want along with the URLRequest:

var params:URLVariables = new URLVariables(); =;
params.filename = ride.map_image;
params.path = 'maps/';
var req:URLRequest = new URLRequest( ModelLocator.SERVER_URL + "/php/uploadpic.php");
req.method = URLRequestMethod.GET; = params;

on the server side in php you access the extra variables as: $_REQUEST['path'] and $_REQUEST['filename'] etc

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow