🖥

#Ruby #AWS S3 / upload not UTF-8 ( e.g SJIS ) file / publish presigned

に公開
tempfile = Tempfile.new

csv_string = 'あ,い,う'
File.write(tempfile.path, csv_string, encoding: Encoding::SJIS)

s3_object.upload_file(tempfile.path)
s3_object.upload_file(
             tempfile.path,
               content_disposition: 'attachment; filename="example.csv"',
               content_type: 'text/csv'
           )

tempfile.close
tempfile.unlink

s3_object.presigned_url(:get, expires_in: 60 * 60)

image

ref

Class: Aws::S3::Client — AWS SDK for Ruby V2
https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/2965

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-01-26

Discussion