4

I use the following code to generate URL that allows to download 1 object from AWS S3:


 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();
    }

How can I generate URL that allows to download multiple files from S3?

Ildar Zaripov
  • 491
  • 7
  • 15
  • Your can't. What is the actual problem that you're trying to solve? There may be other solutions. – Parsifal Jan 05 '21 at 14:24
  • @Parsifal users will need to download multiple images, this is for some sort of gallery. Photos are stored in a private s3 bucket. I was thinking if I generate multiple URLs for many users, it will have bad performance. Just recently read article where it was said that AWS SDK doesn't make request to AWS itself to generate URL. So you are right, it is okay to generate many URLs. – Ildar Zaripov Jan 06 '21 at 10:03
  • Possible duplicate of https://stackoverflow.com/questions/36344194/pre-signed-url-for-multiple-files. Long story short, check the AWS documentation for Java specifically. Some languages may / may not be supported for creating a presigned URL for multiple files. – G M Nov 26 '22 at 17:15

0 Answers0