What I am trying to accomplish is to upload some binary data, specifically a ByteArray representing a PNG image, to a server using the URLLoader class in conjunction with UR
It could be possible that contentType
does not refer to what data you send, but to what data you receive. Try to set the requestHeaders
, that should work:
urlRequest.requestHeaders.push(new URLRequestHeader('Content-type', 'multipart/form-data'));
Also, I've found a piece of code where in one of my projects. The code works and sends some binary JPEG data to the server, using POST. I dit it some time ago and I can't explain why I did the things this way, but maybe it helps. I'm pasting it as is:
function sendData(submitPath:String, descriere:String):void {
// building the url request for uploading the jpeg to the server
var header:URLRequestHeader = new URLRequestHeader('Content-type', 'application/octet-stream');
var jpgURLRequest:URLRequest = new URLRequest(submitPath+'/id/'+player.id+'/path/'+player.contentPath.replace('/','')+'/width/'+player.videoWidth+'/height/'+player.videoHeight+'/descriere/'+descriere+'/timp/'+time);
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = screenShot;
// sending the data to the server
var sender:URLLoader = new URLLoader();
sender.load(jpgURLRequest);
}