Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Users

Get raw data (byte array) from flash in Zope

 

 

Zope users RSS feed   Index | Next | Previous | View Threaded


objectvalues at gmail

Nov 25, 2009, 3:30 AM

Post #1 of 5 (1575 views)
Permalink
Get raw data (byte array) from flash in Zope

Hello everyone,

I have a question about how to get raw data sent by a flash
application in Zope (a zope method/function).

The flash application uses the method in the link below to send to the
server an image (jpg):

http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/

Searching through the internet I have found a PHP example that gets
this byte array sent from flash:

http://blog.joa-ebert.com/2006/05/01/save-bytearray-to-file-with-php/

They are getting the date form a header called HTTP_RAW_POST_DATA.


The question is: how can I get this data on the server side in Zope? Becasue:

- REQUEST.form is empty
- HTTP_RAW_POST_DATA is missing
- there is no other key or value in the REQUEST to indicate the value
I am looking for


On my local devel machine I managed to find a solution:

- using Zope 2.10.3 I have enabled use-wsgi (on) (without apache)
- in zope, the method called from flash is something like this:

...
v = REQUEST.environ['wsgi.input']
v.seek(0)
f = open(join(SOME_PATH, 'image.jpg'), 'wb')
f.write(v.read())
f.close()
return '1'

This solution doesn't work on the production environment - Zope 2.11.4
with ZEO (pound and apache in the front of zope as load balancer and
web server).


Is there a way to solve this problem? Any idea is highly appreciated.

Thank you very much,
Dragos


--
Dragos Chirila
objectValues [at] gmail
(+4) 0722 395375
_______________________________________________
Zope maillist - Zope [at] zope
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )


stefan at epy

Nov 25, 2009, 3:59 AM

Post #2 of 5 (1502 views)
Permalink
Re: Get raw data (byte array) from flash in Zope [In reply to]

Try REQUEST.BODYFILE


On 25.11.2009, at 12:30, Dragos Chirila wrote:

> The question is: how can I get this data on the server side in Zope?
> Becasue:
>
> - REQUEST.form is empty
> - HTTP_RAW_POST_DATA is missing
> - there is no other key or value in the REQUEST to indicate the value
> I am looking for

--
Stefan H. Holek
stefan [at] epy




_______________________________________________
Zope maillist - Zope [at] zope
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )


objectvalues at gmail

Nov 25, 2009, 6:58 AM

Post #3 of 5 (1500 views)
Permalink
Re: Get raw data (byte array) from flash in Zope [In reply to]

Doesn't work: AttributeError: BODYFILE


On Wed, Nov 25, 2009 at 1:59 PM, Stefan H. Holek <stefan [at] epy> wrote:
> Try REQUEST.BODYFILE
>
>
> On 25.11.2009, at 12:30, Dragos Chirila wrote:
>
>> The question is: how can I get this data on the server side in Zope?
>> Becasue:
>>
>> - REQUEST.form is empty
>> - HTTP_RAW_POST_DATA is missing
>> - there is no other key or value in the REQUEST to indicate the value
>> I am looking for
>
> --
> Stefan H. Holek
> stefan [at] epy
>
>
>
>
>



--
Dragos Chirila
objectValues [at] gmail
(+4) 0722 395375
_______________________________________________
Zope maillist - Zope [at] zope
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )


objectvalues at gmail

Nov 25, 2009, 10:30 AM

Post #4 of 5 (1487 views)
Permalink
Re: Get raw data (byte array) from flash in Zope [In reply to]

The data is actually received by Zope, but its broken into "pieces".

Please find a sample of the REQUEST.form here
http://media.fourhooks.ro/request_form.jpg

Any hints on how to put the image back together?


On Wed, Nov 25, 2009 at 4:58 PM, Dragos Chirila <objectvalues [at] gmail> wrote:
> Doesn't work: AttributeError: BODYFILE
>
>
> On Wed, Nov 25, 2009 at 1:59 PM, Stefan H. Holek <stefan [at] epy> wrote:
>> Try REQUEST.BODYFILE
>>
>>
>> On 25.11.2009, at 12:30, Dragos Chirila wrote:
>>
>>> The question is: how can I get this data on the server side in Zope?
>>> Becasue:
>>>
>>> - REQUEST.form is empty
>>> - HTTP_RAW_POST_DATA is missing
>>> - there is no other key or value in the REQUEST to indicate the value
>>> I am looking for
>>
>> --
>> Stefan H. Holek
>> stefan [at] epy
>>
>>
>>
>>
>>
>
>
>
> --
> Dragos Chirila
> objectValues [at] gmail
> (+4) 0722 395375
>



--
Dragos Chirila
objectValues [at] gmail
(+4) 0722 395375
_______________________________________________
Zope maillist - Zope [at] zope
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )


objectvalues at gmail

Nov 28, 2009, 11:15 AM

Post #5 of 5 (1455 views)
Permalink
Re: Get raw data (byte array) from flash in Zope [In reply to]

Hi,

The solution is very simple :)

Instead of sending the byte array like in the example, just encode it
as a string and send it in a variable using POST:

- base64 - this doesn;t works all the time... i don't know why
- bin to hex - works all the time

The server side code is like this:

img = REQUEST.form.get('picture', None)
if img is not None and img != '':
img = binascii.unhexlify(img)
img = PIL.Image.open(StringIO(img))
img.save(join(..., 'picture.jpg'))

We made tests with a lot of images, even with images of 10MB size. It works...

Dragos


On Wed, Nov 25, 2009 at 8:30 PM, Dragos Chirila <objectvalues [at] gmail> wrote:
> The data is actually received by Zope, but its broken into "pieces".
>
> Please find a sample of the REQUEST.form here
> http://media.fourhooks.ro/request_form.jpg
>
> Any hints on how to put the image back together?
>
>
> On Wed, Nov 25, 2009 at 4:58 PM, Dragos Chirila <objectvalues [at] gmail> wrote:
>> Doesn't work: AttributeError: BODYFILE
>>
>>
>> On Wed, Nov 25, 2009 at 1:59 PM, Stefan H. Holek <stefan [at] epy> wrote:
>>> Try REQUEST.BODYFILE
>>>
>>>
>>> On 25.11.2009, at 12:30, Dragos Chirila wrote:
>>>
>>>> The question is: how can I get this data on the server side in Zope?
>>>> Becasue:
>>>>
>>>> - REQUEST.form is empty
>>>> - HTTP_RAW_POST_DATA is missing
>>>> - there is no other key or value in the REQUEST to indicate the value
>>>> I am looking for
>>>
>>> --
>>> Stefan H. Holek
>>> stefan [at] epy
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Dragos Chirila
>> objectValues [at] gmail
>> (+4) 0722 395375
>>
>
>
>
> --
> Dragos Chirila
> objectValues [at] gmail
> (+4) 0722 395375
>



--
Dragos Chirila
objectValues [at] gmail
(+4) 0722 395375
_______________________________________________
Zope maillist - Zope [at] zope
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )

Zope users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.