import java.util.Calendar; import java.util.Date; import com.amazonaws.HttpMethod; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; public class PreSignURLGenerator { private final static String BUCKET_NAME = "this-is-not-porn"; private final static String FILE_NAME = "not-porn-media-files/0146ce52-bbd5-4998-9378-35c20ece0000.jpg"; private final static String ACCESS_KEY = "not-telling-you"; private final static String SECRET_KEY = "it-s-a-secret"; /** * @param args */ public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 1000); Date expDate = cal.getTime(); try { BasicAWSCredentials cre = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); AmazonS3 s3 = new AmazonS3Client(cre); String url = s3.generatePresignedUrl(BUCKET_NAME, FILE_NAME, expDate, HttpMethod.GET).toString(); System.out.println(url); } catch (Exception e) { e.printStackTrace(); } } }
FYI:
and required access to Internet/AWS.
Do feedback if you really like this post.