简体   繁体   中英

AWS SDK: Pre-signed URL for multiple file uploads

Is it possible to generate Pre-signed URL for multiple file uploads with AWS SDK?

I am using JavaScript SDK and the code below is working for a single file upload.

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'

const client = new S3Client({ region: 'ap-northeast-1' })
const command = new PutObjectCommand({
  Bucket: 'BUCKET_NAME',
  Key: `public/1/photos/124.jpg`,
})
const signedUrl = await getSignedUrl(client, command, { expiresIn: 3600 })

Iterate over multiple file inputs:

  const urls = await Promise.all(
    ["image1.jpg", "image2.jpg", "image3.jpg"].map((key) => {
      const command = new PutObjectCommand({
        Bucket: "BUCKET_NAME",
        Key: key,
      });

      return getSignedUrl(client, command, { expiresIn: 3600 });
    })
  );

A pre-signed URL is tied to a single file/bucket/method combination. The JS SDK v3 getSignedUrl method returns a single URL ( Promise<string> ). So iteration it is!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM