0
0

More than 1 year has passed since last update.

#Ruby #AWS S3 / upload not UTF-8 ( e.g SJIS ) file / publish presigned url / directly open download file from browser / as text/csv

Last updated at Posted at 2020-01-26
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

チャットメンバー募集

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

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0