简体   繁体   English

aws-sdk ruby​​-使用客户端加密将文件上传到s3

[英]aws-sdk ruby - upload file to s3 with client side encryption

I am trying to encrypt my files before sending to S3 (client side encryption). 我正在尝试将文件加密,然后再发送到S3(客户端加密)。 But the file is not being uploaded correctly. 但是文件没有正确上传。 It opens with an error. 它以错误打开。 Please guide what can be the issue. 请指导可能是什么问题。 I am using aws-sdk version 3. 我正在使用aws-sdk版本3。

Here is my code: 这是我的代码:

s3 = Aws::S3::Encryption::Client.new(encryption_key: Rails.application.secrets.s3_client_key)

bucket_name = "my-bucket"

key = "my_records/record_1.jpg"
File.open('file_path', 'rb') do |file|
   s3.put_object(
     bucket:bucket_name, 
     key:key, 
     body:file
)
end

It looks like you are trying to view an encrypted file through a browser. 您似乎正在尝试通过浏览器查看加密的文件。

http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html

With client side encryption you need to decrypt after retrieving the object. 使用客户端加密时,需要在检索对象后解密。 A browser cannot do the decryption for you. 浏览器无法为您解密。

If you want the object to be encrypted at rest in S3, you can use the server side S3. 如果希望在S3中静态加密对象,则可以使用服务器端S3。

Also It will be encrypted during transit if you use SSL to browser, from there it will get decrypt and browser will show the image. 另外,如果您使用SSL到浏览器,它将在传输过程中被加密,从那里将被解密,浏览器将显示图像。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM