How to encrypt clip attachments before downloading them to S3?

I am working on a Ruby on Rails web application. The user can upload files and they are saved in Amazons S3. I use paperclip pearls to upload files.

How can I encrypt files using AES256 before saving them? I know that S3 has server-side encryption, but actually it does not work for me, because I open the site in a mobile application and want to handle decryption on the client.

I know that I can use paperclip processors or before_post_process methods, but how can I get a downloadable file and modify it?

+4
source share
1 answer

Take a look at this recipe paperclip on asynchronous to load on S3. You can use this and then change the callback code to:

def upload_to_s3 self.remote_avatar = encrypt(local_avatar.to_file) self.local_avatar = nil self.save! end 

Where the encrypt method is an AES256 function.

It might be worth a look at this extra stone for CarrierWave , if you are not set to clip, it can save some time.

+1
source

Source: https://habr.com/ru/post/1446185/


All Articles