473,664 Members | 3,035 Online
Bytes | Software Development & Data Engineering Community
+ 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 2719
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:

http://www.pythonware.com/products/pil/
Sep 26 '08 #2
rs********@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

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

</F>

Sep 27 '08 #3

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.
Sep 28 '08 #4
rs********@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, 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
2052
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 this case is a gif-file. I've implemented my own class loader which extends the java ClassLoader and overrides some methods for deriving classes from the jar-bytearray. Is there anyone who have any suggestion on how to create an URL-object from...
3
9724
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 large)? I am considering an 8K or 16K Buffer. The files sizes are random but range between 8K - 100K with the occasional files being several megs. Example: int _READBUFFER_ = 1024 ; fi = new FileInfo( args ) ;
1
1330
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 only 1000 items long Array(0-999), and i just want to have the positions 1000-2000 from the stream! How can i realize it that the bytes 1000-2000 are written to an Array of
2
1911
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
2617
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 voicemail. Does anyone know how to contact them? http://www.lcrhq.co.uk/ What I want to tell them is that I have an automatic press release monitoring program, Marvin, which tracks press releases for over 80
5
9090
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 XPath or XmlReader, grab the attribute data, dump it into the database. Once all that's done i blow away all the xml files and start the whole process over next time i need to read fresh data from the API.
2
1995
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
4042
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 fs.Read(ByteArray, 0, fs.Length)
0
2883
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 ?myResp.GetResponseStream() {System.Net.ConnectStream}
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
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 we have to send another system
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.