Django encrypt FileField before saving it

Viewed 202

I'm trying to save pdfs in the disk with django which is easy. However I want to encrypt them before saving them. As far as i know i should rewrite the save of the model to encrypt the file content before making the super().save()

The problem is that i'm not managing to encryopt the content, i've tried with:

self.file.write(f.encrypt(self.file.read()))

However it does not modify anything. I'm usinf fernet for encryptation however that is not the problem because if read the content is readed properly and if i encrypted it it works but the write is not storing anything. In fact once i call the super function it stored in plain. I'm not seeing with the debbuger where the content of the file is to modify it or how should i do it.

Thanks!

0 Answers
Related