edit-icon download-icon

Authorized access

Last Updated: Dec 21, 2017

SDK supports the signing of a URL with a validity period or a public resource URL so that the URL can be transferred to a third party for authorized access.

Sign a private resource URL with a validity period

For a bucket or an object not assigned the public-read permission, the following interface can be called to obtain a signed URL to access the bucket or object:

  1. NSString * constrainURL = nil;
  2. // sign constrain url
  3. OSSTask * task = [client presignConstrainURLWithBucketName:@"<bucket name>"
  4. withObjectKey:@"<object key>"
  5. withExpirationInterval: 30 * 60];
  6. if (!task.error) {
  7. constrainURL = task.result;
  8. } else {
  9. NSLog(@"error: %@", task.error);
  10. }

Sign a public resource URL

For a bucket or an object with the public-read permission, the following interface can be called to obtain a public URL to access the bucket or object:

  1. NSString * publicURL = nil;
  2. // sign public URL
  3. task = [client presignPublicURLWithBucketName:@"<bucket name>"
  4. withObjectKey:@"<object key>"];
  5. if (!task.error) {
  6. publicURL = task.result;
  7. } else {
  8. NSLog(@"sign url error: %@", task.error);
  9. }
Thank you! We've received your feedback.