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