filesize under Amazon SES 10MB limit

pull/1/head
Andromeda Yelton 2013-07-05 08:43:02 -04:00
parent 0788dee930
commit 8ff9bfc52f
1 changed files with 13 additions and 10 deletions

View File

@ -2561,19 +2561,22 @@ def send_to_kindle(request, kindle_ebook_id, javascript='0'):
title = ebook.edition.title
title = title.replace(' ', '_')
# TO FIX rigorously:
# Amazon SES has a 10 MB size limit (http://aws.amazon.com/ses/faqs/#49) in messages sent
# to determine whether the file will meet this limit, we probably need to compare the
# size of the mime-encoded file to 10 MB. (and it's unclear exactly what the Amazon FAQ means precisely by
# MB either: http://en.wikipedia.org/wiki/Megabyte)
# http://www.velocityreviews.com/forums/t335208-how-to-get-size-of-email-attachment.html might help
"""
TO FIX rigorously:
Amazon SES has a 10 MB size limit (http://aws.amazon.com/ses/faqs/#49) in messages sent
to determine whether the file will meet this limit, we probably need to compare the
size of the mime-encoded file to 10 MB. (and it's unclear exactly what the Amazon FAQ means precisely by
MB either: http://en.wikipedia.org/wiki/Megabyte) http://www.velocityreviews.com/forums/t335208-how-to-get-size-of-email-attachment.html might help
# for the moment, we will hardwire a 8x10^6 limit in filesize, which will properly block Oral Literature in Africa
# while leaving our other campaign-unglued books.
for the moment, we will hardwire a 749229 limit in filesize:
* assume conservative size of megabyte, 1000000B
* leave 1KB for headers
* mime encoding will add 33% to filesize
This won't perfectly measure size of email, but should be safe, and is much faster than doing the check after download.
"""
filehandle = urllib.urlopen(ebook.url)
filesize = int(filehandle.info().getheaders("Content-Length")[0])
if filesize > 8000000:
if filesize > 7492232:
logger.info('ebook %s is too large to be emailed' % kindle_ebook_id)
return local_response(request, javascript, 0)