通过urlfetch将图像插入Python Google App Engine Sdk中的Picasa
我尝试通过Google App Engine Sdk将Flex应用程序中的图像插入到picasa网站。我想做一个简单的urlfetch而不是python客户端库。我的代码如下:
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
})
谢谢,约翰逊。
没有找到相关结果
已邀请:
1 个回复
蕉衫