This document provides an overview of SDK code samples related to generating pre-signed object links.
For the parameters and method descriptions of all the APIs in the SDK, please see SDK API Reference.
Objective-C
QCloudGetPresignedURLRequest* getPresignedURLRequest = [[QCloudGetPresignedURLRequest alloc] init];
// Bucket name in the format: `BucketName-APPID`
getPresignedURLRequest.bucket = @"examplebucket-1250000000";
// HTTP method of the request using a pre-signed URL. Valid values (case-sensitive): @"GET", @"PUT", @"POST", @"DELETE"
getPresignedURLRequest.HTTPMethod = @"PUT";
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "dir1/object1"
getPresignedURLRequest.object = @"exampleobject";
[getPresignedURLRequest setFinishBlock:^(QCloudGetPresignedURLResult * _Nonnull result,
NSError * _Nonnull error) {
// Pre-signed URL
NSString* presignedURL = result.presienedURL;
}];
[[QCloudCOSXMLService defaultCOSXML] getPresignedURL:getPresignedURLRequest];
Note:
For more samples, please visit GitHub.
Swift
let getPresign = QCloudGetPresignedURLRequest.init();
// Bucket name in the format: `BucketName-APPID`
getPresign.bucket = "examplebucket-1250000000" ;
// HTTP method of the request using a pre-signed URL. Valid values (case-sensitive):
// @"GET", @"PUT", @"POST", @"DELETE"
getPresign.httpMethod = "PUT";
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "dir1/object1"
getPresign.object = "exampleobject";
getPresign.setFinish { (result, error) in
if let result = result {
let url = result.presienedURL
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getPresignedURL(getPresign);
Note:
For more samples, please visit GitHub.
Objective-C
QCloudGetPresignedURLRequest* getPresignedURLRequest = [[QCloudGetPresignedURLRequest alloc] init];
// Bucket name in the format: `BucketName-APPID`
getPresignedURLRequest.bucket = @"examplebucket-1250000000";
// HTTP method of the request using a pre-signed URL. Valid values (case-sensitive): @"GET", @"PUT", @"POST", @"DELETE"
getPresignedURLRequest.HTTPMethod = @"GET";
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "dir1/object1"
getPresignedURLRequest.object = @"exampleobject";
[getPresignedURLRequest setFinishBlock:^(QCloudGetPresignedURLResult * _Nonnull result,
NSError * _Nonnull error) {
// Pre-signed URL
NSString* presignedURL = result.presienedURL;
}];
[[QCloudCOSXMLService defaultCOSXML] getPresignedURL:getPresignedURLRequest];
Note:
For more samples, please visit GitHub.
Swift
let getPresign = QCloudGetPresignedURLRequest.init();
// Bucket name in the format: `BucketName-APPID`
getPresign.bucket = "examplebucket-1250000000" ;
// HTTP method of the request using a pre-signed URL. Valid values (case-sensitive):
// @"GET", @"PUT", @"POST", @"DELETE"
getPresign.httpMethod = "GET";
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "dir1/object1"
getPresign.object = "exampleobject";
getPresign.setFinish { (result, error) in
if let result = result {
let url = result.presienedURL
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getPresignedURL(getPresign);
Note:
For more samples, please visit GitHub.
Was this page helpful?