Saving binary data to a file on the model through django boto s3 repositories

I am pulling a pdf file from the echosign API which gives me the bytes of the file.

I am trying to take these bytes and save them in boto s3 supported by FileField. I was not lucky.

It was the closest that I received, but errors while maintaining the "dynamics", and pdf, although written in S3, seems to be corrupted.

Here speakeris the instance of my model, and fileData is the string of "bytes" returned from the echosign api

afile = speaker.the_file = S3BotoStorageFile(filename, "wb", S3BotoStorage())
afile.write(fileData)
afile.close()
speaker.save()
+5
source share
1 answer

I'm closer!

    content = ContentFile(fileData)
    speaker.profile_file.save(filename, content)
    speaker.save()

, FileField S3BotoStorage, , datadin. , ( ). , .

echosign: https://secure.echosign.com/static/apiv14/sampleXml/getDocuments-response.xml

ContentFile fileData. , base64. !

Update

!

, , . . , :

content = ContentFile(base64.b64decode(fileData))
speaker.profile_file.save(filename, content)
speaker.save()
+4

All Articles