This document provides code samples to obtain an object URL.
Note:
- This API is used to query the URL to access an object. It does not verify whether the object exists or not.
- The URL generated using this API cannot be used to access private-read objects. For such objects, you can generate a URL by referring to Generating Pre-Signed URLs.
For parameters and method description of all APIs in the SDK, please see SDK API Reference.
Objective-C
QCloudGetPresignedURLRequest* getPresignedURLRequest = [[QCloudGetPresignedURLRequest alloc] init];
// Generate an unsigned URL
getPresignedURLRequest.isUseSignature = false:
// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.intl.cloud.tencent.com/cos5/bucket
getPresignedURLRequest.bucket = @"examplebucket-1250000000";
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
getPresignedURLRequest.object = @"exampleobject";
[getPresignedURLRequest setFinishBlock:^(QCloudGetPresignedURLResult * _Nonnull result,
NSError * _Nonnull error) {
// Pre-Signed URL
NSString* presignedURL = result.presienedURL;
}];
[[QCloudCOSXMLService defaultCOSXML] getPresignedURL:getPresignedURLRequest];
Note:For the complete sample, go to GitHub.
Swift
let getPresign = QCloudGetPresignedURLRequest.init();
// Generate an unsigned URL
getPresign.isUseSignature = false;
// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.intl.cloud.tencent.com/cos5/bucket
getPresign.bucket = "examplebucket-1250000000" ;
// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
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 the complete sample, go to GitHub.
Apakah halaman ini membantu?