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

3

6

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?

How do I protect against someone uploading a 1GB file and eating up my quota?

Whaley answered 5/8, 2010 at 19:49 Comment(0)
H
7

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.

Hunk answered 13/9, 2011 at 7:18 Comment(0)
J
2

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.

Jornada answered 6/8, 2010 at 10:5 Comment(1)
I filed a feature request - code.google.com/p/googleappengine/issues/detail?id=3554Whaley
B
-1

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
}
Babism answered 6/8, 2010 at 9:40 Comment(3)
As the OP said, this is using the App Engine blobstore API, so this doesn't apply.Jornada
And from where he'll call blobstore API? from within a servlet? Do you tell me which line of code is not applicable in App Engine?Babism
if you read the docs on the blobstore (which is different than the datastore) you'll see that none of the lines above are applicable - your servlet doesn't accept the data from the user, the blobstore does. the form the user submits goes directly to the blobstore, not your servlet. code.google.com/appengine/docs/java/blobstore/overview.htmlRegional

© 2022 - 2024 — McMap. All rights reserved.