Google App Engine Python:获取服务器端的图片上传大小

时间:2010-05-14 03:42:44

标签: python image google-app-engine

我正在构建一个允许用户上传图片的Google App Engine应用程序;我一切正常,但我很难找到一种方法来确保用户不会上传太大的图像(因为我正在调整图像大小,所以这会崩溃我的python脚本)。 当用户上传大图片时,我收到此错误

RequestTooLargeError: The request to API call images.Transform() was too large.

我知道GAE允许它的图像API存在大小限制,我只是想找到一种方法来处理这个服务器端;

的内容
if (image is too large):
    inform user
else:
    proceed

我没有运气找到正确的python代码来做到这一点;谁能帮助我?

2 个答案:

答案 0 :(得分:5)

from google.appengine.runtime import apiproxy_errors

...

try:
    #the code you are getting the error at
except apiproxy_errors.RequestTooLargeError, message:
    print message # or something else

答案 1 :(得分:1)

我不确定我是否完全了解你的问题,但尝试一下会有效吗?

try:    
    images.Transform()
except Transform.RequestTooLargeError:
    inform
else:
    proceed