0
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 5 years have passed since last update.

AWS-sdkでサイズが大きいファイルをS3にアップロードする方法

0
Posted at

起きたこと

webアプリで5MBくらいのファイルをS3にアップロードしようとした時に

.js
const uploadFile = fs.readFileSync("/hoge/hogehoge.zip");
const params = {
      Bucket: "test_bucket",
      Key: "hoge/hoge.zip",
      Body: uploadFile
    };
return S3Client.upload(params).promise();

って書いたらreadFileSyncに時間がかかりすぎてブラウザがタイムアウトを起こしてしまう問題が発生しました。

解決方法

stackoverflow様によると

.js
const uploadFile = fs.createReadStream("/hoge/hogehoge.zip");

ってしたら一瞬でアップロードできてS3を確認するとファイルサイズは元のファイルサイズと同じで中身も同じでした!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?