开发者

as3: How to upload bitmap data to server using httpRequest

开发者 https://www.devze.com 2022-12-20 20:49 出处:网络
I captured screenshot of my ui element, and would like to send it to server, using httpService. Currently I am doing the following:

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);
va开发者_如何学Cr 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: {}


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号