diff --git a/geocamTiePoint/defaultSettings.py b/geocamTiePoint/defaultSettings.py index 73d232d..6bc63fb 100644 --- a/geocamTiePoint/defaultSettings.py +++ b/geocamTiePoint/defaultSettings.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 + diff --git a/geocamTiePoint/views.py b/geocamTiePoint/views.py index 1a99d1f..69f9183 100644 --- a/geocamTiePoint/views.py +++ b/geocamTiePoint/views.py @@ -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)