1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Go言語でS3から直接ダウンロードするURLを発行する時にファイル名を差し替える

Last updated at Posted at 2019-12-13

ちょっとハマったのでメモ

差し替えのファイル名は"response-content-disposition"にセットする必要がある。
object inputのparamでResponseContentDispositionを指定できるようなのでそちらで指定する


  svc := s3.New([s3 setting params])

  // 日本語ファイル名にしたい場合はURLエンコードが必要
  fileName := fmt.Sprintf("attachment; filename=%s", url.QueryEscape("ファイル名"))

  params := &s3.GetObjectInput{
    Bucket:                     aws.String([bucket name]),
    Key:                        aws.String([key]),
    ResponseContentDisposition: &fileName,
  }

  req, _ := svc.GetObjectRequest(params)
  // 期限付きURLを発行
  downloadURL, err := req.Presign(10 * time.Minute)

参考にさせていただいたページ
https://qiita.com/kitar/items/166896357f50f4fe0a95
https://stackoverflow.com/questions/40434525/download-s3-file-with-a-different-filename-than-the-bucket-key

1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?