Pre-signed URL

Last updated: 2020-02-28 19:12:13

PDF

This document focuses on how to upload, download or perform other operations through a pre-signed URL (SDK or server can generate a pre-signed URL for upload, download or other operations).

  • We assume that you have followed the Quick Start The instructions in the documentation complete the process of downloading, installing, and initializing SDK.
  • When querying, it is recommended to use Command+F to find the API you want to query, and then see the simple description of the API we give, and copy the example to run in your project.

If you need to understand the function of the interface or the meaning of the parameters, it is recommended to check the comments in the code directly. Xcode supports viewing its definition as Control+Command+D by tapping with three fingers, pressing Force-touch again, or hovering the mouse over a variable.

Step description

  1. Generate an instance of QCloudGetPresignedURLRequest.
  2. Fill in the necessary information, such as the requested Bucket,Object, HTTPMethod, etc.
  3. If an additional HTTP header or parameter is added when using it, the corresponding method in QCloudGetPresignedURLRequest will be called when generating a pre-signed URL.
  4. Call getPresignedURL in QCloudCOSXMLService to make the request and get the pre-signed URL in the result.

QCloudGetPresignedURLRequest parameter description

Parameter name Description Type Required
Bucket Use the bucket name of the pre-signed request, which can be found in the COS console As you can see above, the format is < BucketName-APPID > , such as examplebucket-1250000000 NSString * Yes
Object Use the Object of the pre-signed request. The object key (Key) is the unique identity of the object in Bucket. For example, in the Access domain name of the object examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/text.txt The object key is doc1/text.txt . For more information, please see Object description NSString * Yes
HTTPMethod The HTTP method of the request using the pre-signed URL. Valid values (case sensitive) are: @ "GET", @ "PUT", @ "POST", @ "DELETE" NSString * Yes
ContentType Specify the HTTP body content encoding type for the request and response NSString * No
ContentMD5 The MD5 value of the file NSString * No

If you need to set the header or URL parameter in a request generated using pre-signed URL, you need to do so by the following methods:

/**
 Add a header to the pre-signed request

 @param value   HTTP header value
 @param requestHeader   HTTP header key
 */
- (void)setValue:(NSString * _Nullable)value forRequestHeader:(NSString * _Nullable)requestHeader;

/**
 Add a URL parameter to the pre-signed request

 @param value   Parameter value
 @param requestParameter   Parameter key
 */
- (void)setValue:(NSString * _Nullable)value forRequestParameter:(NSString *_Nullable)requestParameter;

Get an example of a pre-signed URL

QCloudGetPresignedURLRequest* getPresignedURLRequest = [[QCloudGetPresignedURLRequest alloc] init];
getPresignedURLRequest.bucket = @"examplebucket-1250000000";
getPresignedURLRequest.HTTPMethod = @"GET";
getPresignedURLRequest.object = @"exampleobject";

[getPresignedURLRequest setFinishBlock:^(QCloudGetPresignedURLResult * _Nonnull result, NSError * _Nonnull error) {
    NSString* presignedURL = result.presienedURL;
}];

[[QCloudCOSXMLService defaultCOSXML] getPresignedURL:getPresignedURLRequest];

Swift exampl

let getPresign  = QCloudGetPresignedURLRequest.init();
getPresign.bucket = "examplebucket-1250000000" ;
getPresign.httpMethod = "GET";
getPresign.object = "exampleobject";
getPresign.setFinish { (result, error) in
    if error == nil{
        print(result?.presienedURL as Any);
    }}
QCloudCOSXMLService.defaultCOSXML().getPresignedURL(getPresign);