473,468 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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:

http://designreviver.com/tutorials/a...es-from-flash/

Sep 26 '08 #1
4 2713
On 26 Sep., 08:47, rsgallo...@gmail.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:

http://www.pythonware.com/products/pil/
Sep 26 '08 #2
rs********@gmail.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_LENGTH", 0))
if bytes MAX_REQUEST_SIZE:
... report request too large ...

im = sys.stdin.read(bytes)

to deal with query parameters etc, see

http://docs.python.org/lib/module-cgi.html

</F>

Sep 27 '08 #3

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

FieldStorage(None, None, '\xff\xd8\xff\xe0\x00\x10JFIF
\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb
\x00\x84\x00\x05\x03\x04\x04\x04\x03\x05\x04\x04\x 04\x05\x05\x05\x06\x07\x0c
\x08\x07\x07\x07\x07\x0f\x0b\x0b\t\x0c\x11\x0f\x12 \x12\x11\x0f
\x11\x11\x13\x16\x1c\x17\x13\x14\x1a\x15\x11\x11\x 18!\x18\x1a\x1d\x1d
\x1f\x1f\x1f\x13\x17"$"\x1e$\x1c\x1e\x1f\x1e
\x01\x05\x05\x05\x07\x06\x07\x0e\x08\x08\x0e\x1e\x 14\x11\x14\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x 1e\x1e\x1e\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x 1e\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.
Sep 28 '08 #4
rs********@gmail.com wrote:
>
Thanks! I'm using form = cgi.FieldStorage(). When I print out the
contents of form, I get this:

FieldStorage(None, None, '\xff\xd8\xff\xe0\x00\x10JFIF
\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xd b
\x00\x84\x00\x05\x03\x04\x04\x04\x03\x05\x04\x04\ x04\x05\x05\x05\x06\x07\x0c
\x08\x07\x07\x07\x07\x0f\x0b\x0b\t\x0c\x11\x0f\x1 2\x12\x11\x0f
\x11\x11\x13\x16\x1c\x17\x13\x14\x1a\x15\x11\x11\ x18!\x18\x1a\x1d\x1d
\x1f\x1f\x1f\x13\x17"$"\x1e$\x1c\x1e\x1f\x1e
\x01\x05\x05\x05\x07\x06\x07\x0e\x08\x08\x0e\x1e\ x14\x11\x14\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\ x1e\x1e\x1e\x1e\x1e
\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\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.
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, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kristina Engdahl | last post by:
Hello, I'm working with dynamic classloading and have encountered a problem when it comes to defining an URL for a file that is available through a bytearray representing a jar-file. The file in...
3
by: Amy L. | last post by:
Is there a Buffer size that is optimial based on the framework or OS that is optimal when working with chunks of data? Also, is there a point where the buffer size might not be optimal (too...
1
by: Daniel von Fersen | last post by:
When I want to Read the Bytes 1000-2000 from a Stream into a ByteArray using Stream.Read(byteArray,1000,2000) they are written to the positions 1000-2000 in the byteArray. but my Array is...
2
by: Luis Mendes | last post by:
How can I read and write images to SQL server to a field with the type "image". Can´t make DataBound work. Thank's in advance, Luis
19
by: Erik Sandblom | last post by:
Hello I can't read the London & Continental Railways website and they have no email address to complain to. I tried calling them, but got put through to one guy who hung up, and another who had...
5
by: th3dude | last post by:
I've searched quite a bit for this one and i can't find any solid solution for what i'm doing here. Right now i'm geting an xml string from an API, creating an xml file, then read the file with...
2
by: Brad Pears | last post by:
I have a bytearray variable and want to create a temporary file on my hard disk from this bytearray so I can print this data. How do I do this?? Thanks, Brad
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
0
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.