PyAMF ByteArray and writing it to disk

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

PyAMF ByteArray and writing it to disk

Andy-294

From Flex, I loaded the file locally and passed the [‘data’] property to python via PyAMF over cherrypy.

 

I got the ByteArray in python, but I wanted to write this byte array to disk and I could not figure out how to do this.

 

with open(‘newfile.xxx’,w,’) as fd:

  fd.write(….???...)

 

I tried using the various read methods to extract items from the byte array but to no avail.

 

Is there a way to access the raw data as bytes so I can write them to disk ?

 

Andy


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

Re: PyAMF ByteArray and writing it to disk

Jesse Warden-2
# cloud is my view.py
# actionScriptObject is an Object
# actionScriptObject.icon is a ByteArray that is a JPEG
fp = tempfile.mkstemp(dir=cloud.images_root, prefix="pi_", suffix=".jpg")
fp = open(fp[1], "wb+")
fp.write(actionScriptObject.icon.getvalue())
fp.close()

name = fp.name[len(cloud.images_root) + 1:]

icon_name = name
icon_path = "http://%s/images/%s" % (get_host(request), name)

On Thu, Nov 12, 2009 at 11:56 AM, Cooper, Andrew <[hidden email]> wrote:

From Flex, I loaded the file locally and passed the [‘data’] property to python via PyAMF over cherrypy.

 

I got the ByteArray in python, but I wanted to write this byte array to disk and I could not figure out how to do this.

 

with open(‘newfile.xxx’,w,’) as fd:

  fd.write(….???...)

 

I tried using the various read methods to extract items from the byte array but to no avail.

 

Is there a way to access the raw data as bytes so I can write them to disk ?

 

Andy


_______________________________________________
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: PyAMF ByteArray and writing it to disk

Nick Joyce
In reply to this post by Andy-294
pyamf.amf3.ByteArray supports a file and StringIO interface, see http://api.pyamf.org/pyamf.amf3.ByteArray-class.html

An example:

from pyamf.amf3 import ByteArray

ba = ByteArray()

ba.write('foobar')
ba.seek(0)

with open('newfile.xxx', 'wb') as fd:
    fd.write(ba.read())

Nick

On 12 Nov 2009, at 10:56, Cooper, Andrew wrote:

From Flex, I loaded the file locally and passed the [‘data’] property to python via PyAMF over cherrypy.
 
I got the ByteArray in python, but I wanted to write this byte array to disk and I could not figure out how to do this.
 
with open(‘newfile.xxx’,w,’) as fd:
  fd.write(….???...)
 
I tried using the various read methods to extract items from the byte array but to no avail.
 
Is there a way to access the raw data as bytes so I can write them to disk ?
 
Andy
_______________________________________________
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: PyAMF ByteArray and writing it to disk

Andy-294

Thanks for the help.

 

It’s obvious now, but at the time I couldn’t see the wood for the trees.

 

Cheers

Andy

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Nick Joyce
Sent: 12 November 2009 17:16
To: PyAMF general discussion
Subject: Re: [pyamf-users] PyAMF ByteArray and writing it to disk

 

pyamf.amf3.ByteArray supports a file and StringIO interface, see http://api.pyamf.org/pyamf.amf3.ByteArray-class.html

 

An example:

 

from pyamf.amf3 import ByteArray

 

ba = ByteArray()

 

ba.write('foobar')

ba.seek(0)

 

with open('newfile.xxx', 'wb') as fd:

    fd.write(ba.read())

 

Nick

 

On 12 Nov 2009, at 10:56, Cooper, Andrew wrote:



From Flex, I loaded the file locally and passed the [‘data’] property to python via PyAMF over cherrypy.

 

I got the ByteArray in python, but I wanted to write this byte array to disk and I could not figure out how to do this.

 

with open(‘newfile.xxx’,w,’) as fd:

  fd.write(….???...)

 

I tried using the various read methods to extract items from the byte array but to no avail.

 

Is there a way to access the raw data as bytes so I can write them to disk ?

 

Andy

_______________________________________________
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