小编two*_*ace的帖子

无法使用aws_s3(ruby gem)以正确的编码从amazon s3存储桶中读取文件?

在编码'utf-8'并从amazon-s3存储桶中读取文件时,我遇到了问题.

我创建了一个文件.

file = File.open('new_file', 'w', :encoding => 'utf-8')
string = "Some ££££ sings"
file.write(string)
file.close
Run Code Online (Sandbox Code Playgroud)

从本地读取一切都没问题.

open('new_file').read
=> "Some ££££ sings"
Run Code Online (Sandbox Code Playgroud)

现在我使用aws_s3将文件上传到amazon s3.

AWS::S3::S3Object.store('new_file', open('new_file'), 'my_bucket')
=> #<AWS::S3::S3Object::Response:0x2214462560 200 OK>
Run Code Online (Sandbox Code Playgroud)

当我从亚马逊s3读

AWS::S3::S3Object.find('new_file', 'my_bucket').value
=> "Some \xC2\xA3\xC2\xA3\xC2\xA3\xC2\xA3 sings"

open(AWS::S3::S3Object.find('new_file','my_bucket').url).read
=> "Some \xC2\xA3\xC2\xA3\xC2\xA3\xC2\xA3 sings"
Run Code Online (Sandbox Code Playgroud)

我一直在尝试许多仍然无法找到解决方案的东西.

非常感谢所有的帮助

中号

ruby encoding amazon-s3

5
推荐指数
1
解决办法
2233
查看次数

标签 统计

amazon-s3 ×1

encoding ×1

ruby ×1