开发者

App Engine Blobstore - What can I do to limit the size of a file that a user can upload?

What can I do to limit the size of a file that can be uploaded? I know I can limit it client side with SWFUpload, but how can I limit it server side?

H开发者_如何学Cow do I protect against someone uploading a 1GB file and eating up my quota?


App Engine 1.5.4 SDK introduced an option to specify a limit on your blob upload size.

See maxUploadSizeBytes and maxUploadSizeBytesPerBlob of the UploadOptions class.


You can't prohibit people from uploading files that are too large (though this would make a good feature request). What you can do is check the size of the uploaded blob, and immediately delete it if it's too big.


Put the code below in serlet where you are recieving data, before calling datastore API.

// Determine the HTTP method
long maxSize = 1024*1024 * 50; //Limit 50 MB
boolean isPostMethod = request.getMethod().equals("POST");

// Verify the content length
int contentLength = request.getContentLength();
if (isPostMethod && (contentLength < 0 || contentLength > maxSize))
  //posted data size is not in acceptable range
else {
    // Process Data
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜