fix 500 errors with excel files > 500k size limit

werkzeug's internal workings keep files under 500kb in memory, and files
greater than 500kb as a TemporaryFile

(https://github.com/pallets/werkzeug/blob/0.11-maintenance/werkzeug/formparser.py#L38)

when we encounter a CSV or TSV, we call normalise_newlines, which invokes
`.read()`, however when we were passing straight into pyexcel, we called
`file.getvalue()` - this exists on BytesIO (small files) but not on
TemporaryFile objects (large files) - we were seeing 500 errors
This commit is contained in:
Leo Hemsted
2016-10-26 15:44:24 +01:00
parent a93333572f
commit 26a985720c
3 changed files with 12 additions and 7 deletions

View File

@@ -173,18 +173,15 @@ class Spreadsheet():
@classmethod
def from_rows(cls, rows, filename=''):
with StringIO() as converted:
output = csv.writer(converted)
for row in rows:
output.writerow(row)
return cls(converted.getvalue(), filename)
@classmethod
def from_file(cls, file_content, filename=''):
extension = cls.get_extension(filename)
if extension == 'csv':
@@ -195,7 +192,7 @@ class Spreadsheet():
return cls.from_rows(pyexcel.get_sheet(
file_type=extension,
file_content=file_content.getvalue()
file_content=file_content.read()
).to_array(), filename)