Skip to content

POSTing a ByteArray from Flash to

2010 August 16
by Tedb0t

…turns out to be really straightforward using the method (thanks to Brian for the heads-up!):

Flash codeā€”for this example you’ll need the AS3CoreLib JPGEncoder class:

_video = new Video(640, 480);
_camera = Camera.getCamera();
_camera.setMode(640, 480, 30);

_jpegEncoder = new JPGEncoder(60);

_urlReq = new URLRequest();
_urlReq.url = "http://localhost:8080/addImage";
_urlReq.method = URLRequestMethod.POST;

_urlLoader = new URLLoader();

_snapShot = new BitmapData(_camera.width, _camera.height);
_snapShotImage = new Bitmap(_snapShot);
var jpgStream:ByteArray = _jpegEncoder.encode(_snapShot); = jpgStream;

try {
} catch (e:Error) {
	trace("Remote.request caught error: "+e);

And the Python (using

import web

urls = (
  '/addImage', 'addImage'

app = web.application(urls, globals())

class addImage:
    def POST(self):
        data =
        f = open("test.jpg", 'wb')

if __name__ == "__main__":

That’s it!

Related Posts:

Comments are closed.