How to read a jpg bytearray from a Flash AS3 file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rsgalloway@gmail.com

    How to read a jpg bytearray from a Flash AS3 file

    I'm trying to save an image from a Flash AS3 to my server as a jpg
    file. I found some PHP code to do this, but I want to do this in
    Python. I'm not quite sure how to convert the following code to
    Python. It's mainly the $GLOBALS["HTTP_RAW_POST_ DATA"] part I don't
    know how to convert.

    <?php

    if ( isset ( $GLOBALS["HTTP_RAW_POST_ DATA"] )) {

    // get bytearray
    $im = $GLOBALS["HTTP_RAW_POST_ DATA"];

    // save image
    $f = fopen($_GET['name'], 'wb');
    fwrite($f, $jpg);
    fclose($f);

    } else echo 'An error occured.';

    ?>

    source:

    The list of the best ecommerce website designs, giving you an idea of what elements you should be focusing on, and some pointers on how you can provide rich user experience through additional website features.


  • Kay Schluehr

    #2
    Re: How to read a jpg bytearray from a Flash AS3 file

    On 26 Sep., 08:47, rsgallo...@gmai l.com wrote:
    I'm trying to save an image from a Flash AS3 to my server as a jpg
    file. I found some PHP code to do this, but I want to do this in
    Python.
    I'd expect you use AS3 to save the image file ( just looking at Adobes
    AS3 docs on how this works ) and load it with PIL if you want to post-
    process it in Python:


    Comment

    • Fredrik Lundh

      #3
      Re: How to read a jpg bytearray from a Flash AS3 file

      rsgalloway@gmai l.com wrote:
      I'm trying to save an image from a Flash AS3 to my server as a jpg
      file. I found some PHP code to do this, but I want to do this in
      Python. I'm not quite sure how to convert the following code to
      Python. It's mainly the $GLOBALS["HTTP_RAW_POST_ DATA"] part I don't
      know how to convert.
      depends on what framework you're using. if you're using plain CGI, you
      should be able to read the posted data from sys.stdin:

      import sys

      im = sys.stdin.read( )

      f = open(name, 'wb')
      f.write(jpg)
      f.close()

      to make your code a bit more robust, you may want to check the
      content-length before doing the read, e.g.

      import os

      if os.environ.get( "REQUEST_METHOD ") != "POST":
      ... report invalid request ...

      bytes = int(os.environ. get("CONTENT_LE NGTH", 0))
      if bytes MAX_REQUEST_SIZ E:
      ... report request too large ...

      im = sys.stdin.read( bytes)

      to deal with query parameters etc, see

      This module is no longer part of the Python standard library. It was removed in Python 3.13 after being deprecated in Python 3.11. The removal was decided in PEP 594. A fork of the module on PyPI c...


      </F>

      Comment

      • rsgalloway@gmail.com

        #4
        Re: How to read a jpg bytearray from a Flash AS3 file


        Thanks! I'm using form = cgi.FieldStorag e(). When I print out the
        contents of form, I get this:

        FieldStorage(No ne, None, '\xff\xd8\xff\x e0\x00\x10JFIF
        \x00\x01\x01\x0 0\x00\x01\x00\x 01\x00\x00\xff\ xdb
        \x00\x84\x00\x0 5\x03\x04\x04\x 04\x03\x05\x04\ x04\x04\x05\x05 \x05\x06\x07\x0 c
        \x08\x07\x07\x0 7\x07\x0f\x0b\x 0b\t\x0c\x11\x0 f\x12\x12\x11\x 0f
        \x11\x11\x13\x1 6\x1c\x17\x13\x 14\x1a\x15\x11\ x11\x18!\x18\x1 a\x1d\x1d
        \x1f\x1f\x1f\x1 3\x17"$"\x1e$\x 1c\x1e\x1f\x1e
        \x01\x05\x05\x0 5\x07\x06\x07\x 0e\x08\x08\x0e\ x1e\x14\x11\x14 \x1e\x1e
        \x1e\x1e\x1e\x1 e\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e \x1e\x1e
        \x1e\x1e\x1e\x1 e\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e \x1e\x1e
        \x1e\x1e\x1e\x1 e\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\xff \.....

        Which is obviously the binary data of the image I want. How do I
        access this data? I'm used to getting it like this:

        name = form['name'].value

        But I don't think this will work in this case. TIA.


        Comment

        • Tim Roberts

          #5
          Re: How to read a jpg bytearray from a Flash AS3 file

          rsgalloway@gmai l.com wrote:
          >
          >Thanks! I'm using form = cgi.FieldStorag e(). When I print out the
          >contents of form, I get this:
          >
          FieldStorage(No ne, None, '\xff\xd8\xff\x e0\x00\x10JFIF
          >\x00\x01\x01\x 00\x00\x01\x00\ x01\x00\x00\xff \xdb
          >\x00\x84\x00\x 05\x03\x04\x04\ x04\x03\x05\x04 \x04\x04\x05\x0 5\x05\x06\x07\x 0c
          >\x08\x07\x07\x 07\x07\x0f\x0b\ x0b\t\x0c\x11\x 0f\x12\x12\x11\ x0f
          >\x11\x11\x13\x 16\x1c\x17\x13\ x14\x1a\x15\x11 \x11\x18!\x18\x 1a\x1d\x1d
          >\x1f\x1f\x1f\x 13\x17"$"\x1e$\ x1c\x1e\x1f\x1e
          >\x01\x05\x05\x 05\x07\x06\x07\ x0e\x08\x08\x0e \x1e\x14\x11\x1 4\x1e\x1e
          >\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e \x1e\x1e\x1e\x1 e\x1e\x1e
          >\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e \x1e\x1e\x1e\x1 e\x1e\x1e
          >\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e \x1e\x1e\x1e\xf f\.....
          >
          >Which is obviously the binary data of the image I want. How do I
          >access this data? I'm used to getting it like this:
          >
          name = form['name'].value
          >
          >But I don't think this will work in this case. TIA.
          What led you to ask that here, instead of taking 60 seconds to load cgi.py
          in an editor and search for the FieldStorage class?
          --
          Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          Working...