0
我尝试通过Google App Engine Sdk将图像从Flex应用程序插入Picasa Web。我想做一个简单的urlfetch,而不是python客户端库。代码我以下:在Python中将图像插入Picasa Google App Engine Sdk通过urlfetch
def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
result = urlfetch.fetch(url=album_or_uri,
method=urlfetch.POST,
follow_redirects=True,
payload=StringIO(filename_or_handle),
headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
'Content-Length': str(len(filename_or_handle)),
'Content-Type': 'image/jpeg',
'Slug': title
})
数据传递给“filename_or_handle”是一个ByteArray图像。但是,这并不成功。我不知道问题是什么。请指教。谢谢。
该溶液以下:
def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
image = filename_or_handle.read()
contentLength = len(image)
result = urlfetch.fetch(url=album_or_uri,
method=urlfetch.POST,
follow_redirects=True,
payload=image,
headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
'Content-Length': contentLength,
'Content-Type': 'image/jpeg',
'Slug': title
})
谢谢,约翰逊。
@Johnson,谢谢你的回复。我通过pyamf从flex应用程序传递数据。该图像作为ByteArray加载到Flex应用程序中,并将其传递给App Engine。 base64只是一个测试。请参阅更新。 – michael 2011-04-06 01:40:41
@michael我在更新后回答了问题。正如我所说的,您应该将图像数据作为原始字符串加载,并直接作为有效载荷传入。并提供更多的细节,如果你仍然有麻烦。 – 2011-04-06 01:46:21
@约翰逊,也许这是一个愚蠢的问题。在我的情况下,字节数组图像数据是可以接受的。谢谢。 – michael 2011-04-06 01:57:03