Saving binary data into file on model via django storages boto s3

Viewed 4844

I'm pulling back a pdf from the echosign API, which gives me the bytes of a file.

I'm trying to take those bytes and save them into a boto s3 backed FileField. I'm not having much luck.

This was the closest I got, but it errors on saving 'speaker', and the pdf, although written to S3, appears to be corrupt.

Here speaker is an instance of my model and fileData is the 'bytes' string returned from the echosign api

afile = speaker.the_file = S3BotoStorageFile(filename, "wb", S3BotoStorage())
afile.write(fileData)
afile.close()
speaker.save()
1 Answers
Related