I would like to limit the size during a file upload according to the next requirements:
1- Client side ( this is almost impossible unless using client plugins such as Flash or Applets ) so I discard this one
2- On the server side, can I know the size of a file / image / video before storing it in the database?
Thanks!
If you're using the Google Blobstore (which you probably will be on App Engine) then I think you're in a little bit of difficulty. As this post states your option is to immediately check the File Size and delete it if too large. Perhaps architecturally it is difficult for Google to offer validation on the BlobStore before the data is stored. I don't know.
Perhaps you want to star the issue on the Google App Engine Issue Tracker. It's unclear if you are using Java or Python, but if you look at the relevant Google API Docs you can determine how to check the size of the Blob entries.
With the Blobstore service, currently there is no way to limit the file size upload (open issue here).
Storing your data using a simple BlobProperty, you could check the size of the blob after the upload with
len(uploaded_blob)
.EDIT:
this is now fixed
Since release 1.5.4
create_upload_url
takes additional optional arguments that can limit the upload sizeAs I get it
max_bytes_per_blob
limits the size of each file being uploaded, whilemax_bytes_total
limits the total size of all files uploaded in one request. For details see https://developers.google.com/appengine/docs/python/blobstore/functionsFor example to limit the upload size to 5MB, call it like this:
If the upload size is larger than the limit, HTTP status 413 (Request Entity Too Large) is returned. If you need, you can intercept it in jQuery like this: