Best Code looks like out of 2/3 responses
unknown
plain_text
a year ago
883 B
1
Indexable
Never
import com.amazonaws.HttpMethod; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; AmazonS3 s3Client = new AmazonS3Client(yourAwsCredentials); // Define the S3 bucket and object key String bucketName = "your-bucket-name"; String objectKey = "your-object-key"; // Define the expiration time for the URL (1 hour in milliseconds) long expirationMillis = System.currentTimeMillis() + 60 * 60 * 1000; // 1 hour // Create a request to generate the pre-signed URL GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey) .withMethod(HttpMethod.GET) .withExpiration(new Date(expirationMillis)); // Generate the pre-signed URL URL preSignedUrl = s3Client.generatePresignedUrl(generatePresignedUrlRequest);