2 questions about pyamf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

2 questions about pyamf

Fet Biz
I use the pyamf to transfer data between the GAE and flash client.
The data was sent from GAE to swf with amf3.encode(a_dict)
I have two problems that happen to me:
1) . "\" causes sending problem from swf to javascript.
In the sending data (a dictionary) , one of the value is an array of
strings (urls).
If one of the urls contains "\", the swf has no problem to receive and decode,
but the decoded data was failed to pass to javascript with
ExternalInterface.call.
To work around, the url (string) has to be quoted by urllib.quote().
No idea about which one should be responsible for this problem.
The amf or the swf-javascript interface?
 (I think it maybe the swf-javascript IPC, but I have tried the
IE8/Firefox/Chrome, all the same)

2). sending binary data from the GAE to swf.
Supose IMG* are the strings in python of some jpg pictures, then the "data"
data = amf3.encode({'images':[IMG1,IMG2,....]})
can not be received and decoded correctly by the swf.
I have to convert the IMG* to amf3.ByteArray, then sends the list of
amf3.ByteArray instances.
My question is:
2.1) Am i doing it the right way?
2.2) Is there any more efficient method to generate the ByteArray from
the binary data?
Currently I iterate every single byte in the binary chunk and push
them into the ByteArray with writeUnsignedByte(ord(c)).

Thanks in advance.
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 2 questions about pyamf

Simon Bierbaum-2
Hi there,

concerning your second problem, is it really necessary to send the  
raw data? I.e., are you actually modifying the data in your Flash  
client, or do you just display the image? If so, it's a lot easier to  
just transmit the images' URLs to Flash and use URLLoader or Flex'  
Image class or somesuch (I'm no too proficient in pure Flash). Flash  
would then send a regular HTTP request to your server to fetch the  
image.

Cheers, Simon

Am 07.01.2010 um 09:55 schrieb biziap biziap:

> I use the pyamf to transfer data between the GAE and flash client.
> The data was sent from GAE to swf with amf3.encode(a_dict)
> I have two problems that happen to me:
> 1) . "\" causes sending problem from swf to javascript.
> In the sending data (a dictionary) , one of the value is an array of
> strings (urls).
> If one of the urls contains "\", the swf has no problem to receive  
> and decode,
> but the decoded data was failed to pass to javascript with
> ExternalInterface.call.
> To work around, the url (string) has to be quoted by urllib.quote().
> No idea about which one should be responsible for this problem.
> The amf or the swf-javascript interface?
>  (I think it maybe the swf-javascript IPC, but I have tried the
> IE8/Firefox/Chrome, all the same)
>
> 2). sending binary data from the GAE to swf.
> Supose IMG* are the strings in python of some jpg pictures, then  
> the "data"
> data = amf3.encode({'images':[IMG1,IMG2,....]})
> can not be received and decoded correctly by the swf.
> I have to convert the IMG* to amf3.ByteArray, then sends the list of
> amf3.ByteArray instances.
> My question is:
> 2.1) Am i doing it the right way?
> 2.2) Is there any more efficient method to generate the ByteArray from
> the binary data?
> Currently I iterate every single byte in the binary chunk and push
> them into the ByteArray with writeUnsignedByte(ord(c)).
>
> Thanks in advance.
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 2 questions about pyamf

Nick Joyce
In reply to this post by Fet Biz
On 7 Jan 2010, at 08:55, biziap biziap wrote:

> I use the pyamf to transfer data between the GAE and flash client.
> The data was sent from GAE to swf with amf3.encode(a_dict)
> I have two problems that happen to me:
> 1) . "\" causes sending problem from swf to javascript.
> In the sending data (a dictionary) , one of the value is an array of
> strings (urls).
> If one of the urls contains "\", the swf has no problem to receive and decode,
> but the decoded data was failed to pass to javascript with
> ExternalInterface.call.
> To work around, the url (string) has to be quoted by urllib.quote().
> No idea about which one should be responsible for this problem.
> The amf or the swf-javascript interface?
> (I think it maybe the swf-javascript IPC, but I have tried the
> IE8/Firefox/Chrome, all the same)

AMF does not use " as string boundaries so there is no need to handle '\' as a special case (length of the string is encoded before the string bytes). I would focus your efforts at the swf-javascript interface as the source of the problem.

>
> 2). sending binary data from the GAE to swf.
> Supose IMG* are the strings in python of some jpg pictures, then the "data"
> data = amf3.encode({'images':[IMG1,IMG2,....]})
> can not be received and decoded correctly by the swf.
> I have to convert the IMG* to amf3.ByteArray, then sends the list of
> amf3.ByteArray instances.
> My question is:
> 2.1) Am i doing it the right way?

Indeed if you need to send binary data, the only way to do it is to encode it some form (e.g. base64). AMF automatically supports this through the ByteArray type so you are doing it the correct 'AMF' way.

> 2.2) Is there any more efficient method to generate the ByteArray from
> the binary data?
> Currently I iterate every single byte in the binary chunk and push
> them into the ByteArray with writeUnsignedByte(ord(c)).

You can supply the raw bytes for the ByteArray in the constructor, e.g.:

from pyamf.amf3 import ByteArray

bytes = '\x00\x01\x02\x03\x04\x05'
ba = ByteArray(bytes)

assert ba.getvalue() == bytes

Cheers,

Nick
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users