Skip to content

Commit

Permalink
Implements file size limit.
Browse files Browse the repository at this point in the history
Rigs PDF import so that it can be disabled from settings
  • Loading branch information
deleted committed Oct 25, 2012
1 parent 4f712d6 commit c13cb5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions geocamTiePoint/defaultSettings.py
Expand Up @@ -4,6 +4,11 @@
# All Rights Reserved. # All Rights Reserved.
# __END_LICENSE__ # __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 # default initial viewport for alignment interface. if we can detect the
# user's position we'll use that instead. these bounds cover the # user's position we'll use that instead. these bounds cover the
# continental US. # continental US.
Expand Down Expand Up @@ -57,3 +62,4 @@
# aligned tiles from public overlays can be viewed by any non-logged-in # aligned tiles from public overlays can be viewed by any non-logged-in
# user, even though the app is in private beta. # user, even though the app is in private beta.
GEOCAM_TIE_POINT_PUBLIC_BY_DEFAULT = True GEOCAM_TIE_POINT_PUBLIC_BY_DEFAULT = True

12 changes: 9 additions & 3 deletions geocamTiePoint/views.py
Expand Up @@ -113,7 +113,7 @@ def overlayDelete(request, key):




def validOverlayContentType(contentType): 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 # this will change to False when pdf conversion goes away
return True return True
if contentType.startswith('image/'): if contentType.startswith('image/'):
Expand Down Expand Up @@ -174,6 +174,9 @@ def overlayNewJSON(request):
# either way we're not going to deal with it # either way we're not going to deal with it
logging.error( "Non-image content-type:" + response.headers['Content-Type'].split('/')[0] ) 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.") 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()) imageFB = StringIO(response.read())
imageType = response.headers['Content-Type'] imageType = response.headers['Content-Type']
imageName = form.cleaned_data['imageUrl'].split('/')[-1] imageName = form.cleaned_data['imageUrl'].split('/')[-1]
Expand All @@ -182,10 +185,13 @@ def overlayNewJSON(request):
imageFB = imageRef.file imageFB = imageRef.file
imageType = imageRef.content_type imageType = imageRef.content_type
imageName = imageRef.name 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) 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 # convert PDF to raster image
pngData = pdf.convertPdf(imageFB.read()) pngData = pdf.convertPdf(imageFB.read())
imageData.image.save('dummy.png', ContentFile(pngData), save=False) imageData.image.save('dummy.png', ContentFile(pngData), save=False)
Expand Down

0 comments on commit c13cb5e

Please sign in to comment.