Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit fba8599

Browse files
committed
Rough stab at a 400MB limit on PDF uploads for #99
1 parent 877293a commit fba8599

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

documentcloud/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,16 @@ def upload(
261261
"""
262262
# Required parameters
263263
if hasattr(pdf, 'read'):
264+
size = os.fstat(pdf.fileno()).st_size
264265
params = {'file': pdf}
265266
else:
267+
size = os.path.getsize(pdf)
266268
params = {'file': open(pdf, 'rb')}
269+
# Enforce file size limit of the DocumentCloud API
270+
if size >= 399999999:
271+
raise ValueError("The pdf you have submited if over the \
272+
DocumentCloud API's 400MB file size limit. Split it into smaller pieces\
273+
and try again.")
267274
# Optional parameters
268275
if title:
269276
params['title'] = title

0 commit comments

Comments
 (0)