edit-icon download-icon

Is there a JAVA code example of presigned URL?

Last Updated: Sep 27, 2017

Example codes of the presigned URL are as follows:

  1. // Generate a presigned URL
  2. Date expires = new Date (new Date().getTime() + 1000 * 60); // 1 minute to expire
  3. GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
  4. generatePresignedUrlRequest.setExpiration(expires);
  5. URL url = client.generatePresignedUrl(generatePresignedUrlRequest);
  6. System.out.println(url.toString());

This section of code assumes that the object with the specified bucketName and key has been uploaded to the OSS, and the users can set the expiration time of expires.More detailed operations can be found in help on OSSClient#generatePresignedUrl and GeneratePresignedUrlRequest.

Thank you! We've received your feedback.