Advertisement
Guest User

Untitled

a guest
May 31st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public static String getPreSignedURL(String url) {
  2. java.util.Date expiration = new java.util.Date();
  3. long msec = expiration.getTime();
  4. msec += 1000 * 60 * 5; // 5 minutes
  5. expiration.setTime(msec);
  6.  
  7. AWSCredentials myCredentials = new BasicAWSCredentials(
  8. AppConstants.AWS_ACCESS_KEY_ID, AppConstants.AWS_SECRET_KEY_ID);
  9. AmazonS3 s3client = new AmazonS3Client(myCredentials);
  10. s3client.setEndpoint(AppConstants.ENDPOINT_S3);
  11. GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(
  12. AppConstants.BUCKET_NAME, url.replace(AppConstants.OBJECT_NAME_FILTER, ""));
  13. request.setExpiration(expiration);
  14. URL objectURL = s3client.generatePresignedUrl(request);
  15. return objectURL.toString();
  16. }
  17.  
  18. var presignedUrl: AWSTask = AWSTask()
  19. let expiration = NSDate().dateByAddingTimeInterval(5*60)
  20.  
  21.  
  22. let credential = AWSStaticCredentialsProvider.init(accessKey: AWS_ACCESS_KEY_ID, secretKey: AWS_SECRET_KEY_ID)
  23. let configuration = AWSServiceConfiguration.init(region:.USEast1, credentialsProvider: credential)
  24.  
  25. //print("%@",configuration.endpoint)
  26. //let regionTp = AWSRegionType(s)
  27.  
  28. AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
  29. let urlBuilder = AWSS3PreSignedURLBuilder.defaultS3PreSignedURLBuilder()
  30.  
  31.  
  32. let preSignedURLRequest = AWSS3GetPreSignedURLRequest.init()
  33.  
  34. preSignedURLRequest.key = "10488/01-New_Jack_City_hq.mp3"
  35. preSignedURLRequest.bucket = "damixhub"
  36. preSignedURLRequest.expires = expiration
  37. preSignedURLRequest.HTTPMethod = .GET
  38. presignedUrl = urlBuilder.getPreSignedURL(preSignedURLRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement