Permalink
Browse files

Implements file size limit.

Rigs PDF import so that it can be disabled from settings
  • Loading branch information...
1 parent 4f712d6 commit c13cb5eaaa9823c203ea96988dedc015a078be9d @deleted deleted committed Oct 25, 2012
Showing with 15 additions and 3 deletions.
  1. +6 −0 geocamTiePoint/defaultSettings.py
  2. +9 −3 geocamTiePoint/views.py
@@ -4,6 +4,11 @@
# All Rights Reserved.
# __END_LICENSE__
+MAX_IMPORT_FILE_SIZE = 2097152 # bytes
+
+# This feature is rigged to be disabled due to the planned removal of the Appengine PDF service
+PDF_IMPORT_ENABLED = True
+
# default initial viewport for alignment interface. if we can detect the
# user's position we'll use that instead. these bounds cover the
# continental US.
@@ -57,3 +62,4 @@
# aligned tiles from public overlays can be viewed by any non-logged-in
# user, even though the app is in private beta.
GEOCAM_TIE_POINT_PUBLIC_BY_DEFAULT = True
+
View
@@ -113,7 +113,7 @@ def overlayDelete(request, key):
def validOverlayContentType(contentType):
- if contentType in PDF_MIME_TYPES:
+ if settings.PDF_IMPORT_ENABLED and contentType in PDF_MIME_TYPES:
# this will change to False when pdf conversion goes away
return True
if contentType.startswith('image/'):
@@ -174,6 +174,9 @@ def overlayNewJSON(request):
# either way we're not going to deal with it
logging.error( "Non-image content-type:" + response.headers['Content-Type'].split('/')[0] )
return ErrorJSONResponse("The file at this URL does not seem to be an image.")
+ imageSize = int( response.info().get('content-length') )
+ if imageSize > settings.MAX_IMPORT_FILE_SIZE:
+ return ErrorJSONResponse("The submitted file is larger than the maximum allowed size. Maximum size is %d bytes." % settings.MAX_IMPORT_FILE_SIZE)
imageFB = StringIO(response.read())
imageType = response.headers['Content-Type']
imageName = form.cleaned_data['imageUrl'].split('/')[-1]
@@ -182,10 +185,13 @@ def overlayNewJSON(request):
imageFB = imageRef.file
imageType = imageRef.content_type
imageName = imageRef.name
-
+ imageSize = imageRef.size
+ if imageSize > settings.MAX_IMPORT_FILE_SIZE:
+ return ErrorJSONResponse("The submitted file is larger than the maximum allowed size. Maximum size is %d bytes." % settings.MAX_IMPORT_FILE_SIZE)
+
imageData = models.ImageData(contentType=imageType)
- if imageType in PDF_MIME_TYPES:
+ if settings.PDF_IMPORT_ENABLED and imageType in PDF_MIME_TYPES:
# convert PDF to raster image
pngData = pdf.convertPdf(imageFB.read())
imageData.image.save('dummy.png', ContentFile(pngData), save=False)

0 comments on commit c13cb5e

Please sign in to comment.