用于下载多个文件的 AWS S3 预签名 URL

Ild*_*pov 5 java amazon-s3 amazon-web-services

我使用以下代码生成允许从 AWS S3 下载 1 个对象的 URL:


 import com.amazonaws.services.s3.AmazonS3;
 import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;


 private AmazonS3 s3Client;

 public String getDownloadPhotoPresignedRequest(String bucketName, String objectKey) throws Exception {
        java.util.Date expiration = new java.util.Date();
        long expTimeMillis = expiration.getTime();
        expTimeMillis += 1000 * 60 * 5;
        expiration.setTime(expTimeMillis);

        // Generate the presigned URL.
        GeneratePresignedUrlRequest generatePresignedUrlRequest =
                new GeneratePresignedUrlRequest(bucketName, objectKey)
                        .withMethod(HttpMethod.GET)
                        .withExpiration(expiration);
        URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);

        return url.toString();
    }
Run Code Online (Sandbox Code Playgroud)

如何生成允许从 S3 下载多个文件的 URL?