For users who have personal segments and who require a URL.
In my case, I needed to get a S3 Object downloadable link for a specific time, since my bucket is private .
I use Spring Cloud AWS, which under the hood uses the AWS SDK for Java and provides an AmazonS3 interface for interacting with S3, use AmazonS3Client if you use the AWS SDK for JAVA instead of AmazonS3 . I just entered AmazonS3, and now I can get the URL of the object, wherever it is needed, but it can be downloaded within 5 minutes, otherwise it will expire.
public String getURL(String key) throws FileNotFoundException { try { return amazonS3.generatePresignedUrl(BUCKET_NAME, key, new DateTime().plusMinutes(5).toDate()).toString(); } catch (AmazonS3Exception exception){ if(exception.getStatusCode() == 404){ throw new FileNotFoundException(key); } else{ throw exception; } } }
Wiqi
source share