views:

308

answers:

1

Hi!

I captured screenshot of my ui element, and would like to send it to server, using httpService.

Currently I am doing the following:

var httpService:HTTPService = new HTTPService();
httpService.method = "POST";
httpService.url = "/admin/compositions/add/";
httpService.addEventListener(ResultEvent.RESULT, onresult);
var bitmapData:BitmapData = new BitmapData(chessBoard.width,chessBoard.height);
var encoder:PNGEncoder = new PNGEncoder();
var data:ByteArray = encoder.encode(bitmapData);
var obj:Object = new Object();
obj.img = data;             
httpService.send(obj);

But I don't see anything in files variable of request (django is the backend) e.g.

POST dictionary

QueryDict: {u'tournament': [u''], u'img': [u'\x89PNG\r\n\x1a\n'], u'sidetomove': [u'true'], u'idea': [u'\u043c\u0430\u0442 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u044f\u0434\u0443'], u'source': [u''], u'complexity': [u'1'], u'opponents': [u'']}

Files dict:

MultiValueDict: {}

+1  A: 

u'\x89PNG\r\n\x1a\n' is header of PNG file so it looks like encoding is not finished but this data is sent to backend.

To have file appear in request.FILES it have to be submitted with multipart/form-data content type (and properly encoded as multipart message).

Łukasz
maybe you can suggest why httpService.contentType = "multipart/form-data";Gives:MultiPartParserError: Invalid boundary in multipart: NoneOn server?
Oleg Tarasenko
It's not only a matter of correct content type, also posted data must be properly encoded as multipart message. http://en.wikipedia.org/wiki/MIME#Multipart_messages here you have example how this should look like. I hink there should be support for that in flex. Quick search resulted with http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/FileReference.html
Łukasz