public function saveJPG( p_bitmapData:BitmapData ):void { // bytearray var pngByteArray:ByteArray = PNGEncoder.encode(p_bitmapData); pngByteArray.position = 0; // boundary var boundary: String = '---------------------------7d76d1b56035e'; // headers var header1: String = '--'+boundary + '\r\n' +'Content-Disposition: form-data; name="Filename"\r\n\r\n' +'picture.jpg\r\n' +'--'+boundary + '\r\n' +'Content-Disposition: form-data; name="Filedata"; filename="picture.jpg"\r\n' +'Content-Type: application/octet-stream\r\n\r\n'; var header2: String = '--'+boundary + '\r\n' +'Content-Disposition: form-data; name="Upload"\r\n\r\n' +'Submit Query\r\n' +'--'+boundary + '--'; //Encoding the two string parts of the header var headerBytes1: ByteArray = new ByteArray(); headerBytes1.writeMultiByte(header1, "ascii"); var headerBytes2: ByteArray = new ByteArray(); headerBytes2.writeMultiByte(header2, "ascii"); //Creating one final ByteArray var sendBytes: ByteArray = new ByteArray(); sendBytes.writeBytes(headerBytes1, 0, headerBytes1.length); sendBytes.writeBytes(pngByteArray, 0, pngByteArray.length); sendBytes.writeBytes(headerBytes2, 0, headerBytes2.length); // request var request: URLRequest = new URLRequest("http://teemu.tuotanto.org/photoeditor/save.php"); request.data = sendBytes; request.method = URLRequestMethod.POST; request.contentType = "multipart/form-data; boundary=" + boundary; // laoder var loader:URLLoader = new URLLoader(); addLoaderListeners(loader); try { loader.load(request); } catch (error: Error) { trace("Unable to load requested document."); } }