Hi am,

You could use something like StringIO which holds data and exposes a
read method so it acts like a file.

Here's an example which creates a new album, adds an image, then
deletes the album. The test image's data is in a string buffer instead
of a file.

import StringIO
import atom
import gdata
import gdata.service

# Create the test image
data = StringIO.StringIO('\xff\xd8\xff\xe0\x00\x10JFIF
\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xe1\x006Exif\x00\x00II*
\x00\x08\x00\x00\x00\x02\x00\x01\x03\x05\x00\x01\x00\x00\x00&
\x00\x00\x00\x03\x03\x01\x00\x01\x00\x00\x00\x00\xff\xff\xff
\x00\x00\x00\x00\xa0\x86\x01\x00\x8f\xb1\x00\x00\xff\xdb\x00C
\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c
\x0b\x0b\x0c\x19\x12\x13\x0f\x14\x1d\x1a\x1f\x1e\x1d\x1a\x1c\x1c $.\'
",#\x1c\x1c(7),01444\x1f\'9=82<.342\xff\xdb\x00C\x01\t\t\t\x0c\x0b\x0c
\x18\r\r\x182!\x1c!
22222222222222222222222222222222222222222222222222\xff
\xc0\x00\x11\x08\x00\x05\x00\x05\x03\x01"\x00\x02\x11\x01\x03\x11\x01\xff
\xc4\x00\x1f
\x00\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\n\x0b\xff
\xc4\x00\xb5\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!
1A\x06\x13Qa\x07"q\x142\x81\x91\xa1\x08#B\xb1\xc1\x15R\xd1\xf0$3br
\x82\t\n\x16\x17\x18\x19\x1a%&
\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
\x83\x84\x85\x86\x87\x88\x89\x8a\x92\x93\x94\x95\x96\x97\x98\x99\x9a
\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa
\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca
\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda
\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea
\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xff\xc4\x00\x1f
\x01\x00\x03\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\n\x0b\xff
\xc4\x00\xb5\x11\x00\x02\x01\x02\x04\x04\x03\x04\x07\x05\x04\x04\x00\x01\x02w
\x00\x01\x02\x03\x11\x04\x05!1\x06\x12AQ\x07aq\x13"2\x81\x08\x14B
\x91\xa1\xb1\xc1\t#3R\xf0\x15br\xd1\n\x16$4\xe1%\xf1\x17\x18\x19\x1a&
\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
\x82\x83\x84\x85\x86\x87\x88\x89\x8a
\x92\x93\x94\x95\x96\x97\x98\x99\x9a
\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa
\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca
\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda
\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea
\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xff\xda\x00\x0c
\x03\x01\x00\x02\x11\x03\x11\x00?\x00\xf6*(\xa2\xbf\r=3\xff\xd9')

# Create the media source object to pull the image data
ms = gdata.MediaSource()
ms.file_handle = data
ms.content_type = 'image/jpeg'
ms.content_length = 689
ms.file_name = 'testimage.jpg'

gd_client = gdata.service.GDataService()
gd_client.email = your_email_address
gd_client.password = your_password
gd_client.service = 'lh2'
gd_client.source = 'Media Tests'
gd_client.ProgrammaticLogin()
gd_client.debug = True

gd_entry = gdata.GDataEntry()
gd_entry.title = atom.Title(text='GData Test Album')
gd_entry.category.append(atom.Category(
    scheme='http://schemas.google.com/g/2005#kind',
    term='http://schemas.google.com/photos/2007#album'))

album_entry = gd_client.Post(gd_entry,
    'http://picasaweb.google.com/data/feed/api/user/' +
gd_client.email)

media_entry = gd_client.Post(None, album_entry.GetFeedLink().href,
media_source = ms)

raw_input('Press enter to delete the new album')

# Now delete the album
album_entry = gd_client.Get(album_entry.id.text)
gd_client.Delete(album_entry.GetEditLink().href)

Is this what you meant by using something other than a file?

Happy coding,

Jeff


On Oct 10, 2:42 pm, Amelie Mercier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm using the gdata python library to interact with Picasa.
>
> How could I use something else than a file handle as my media_source
> in GDataService.Post?
>
> Thanks,
>
> --am


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to