Pre-signed URL

Last updated: 2020-05-13 11:53:37

This document describes how to perform upload, download, and other such operations with a pre-signed URL which can be generated by either the SDK or the server.

  • This document assumes that you have already downloaded, installed, and initialized the SDK as instructed in Getting Started.
  • We recommend using Command+F to search for the API you want to query, check the provided description of the API, and then copy the sample code to your project for execution.

    If you want to learn more about the function of the API or the meanings of its parameters, we recommend directly viewing the comments in the code. In Xcode, you can use a three-finger tap, Force Touch, or you can hover over a variable and press Control+Command+D to see its interpretation.


  1. Generate a QCloudGetPresignedURLRequest instance.
  2. Enter the required information such as the bucket, object, and HTTPMethod of the request.
  3. If you add an additional HTTP header or parameter to the request, you should call the corresponding method in QCloudGetPresignedURLRequest to add them to the pre-signed URL when it is generated.
  4. Call getPresignedURL in QCloudCOSXMLService to send the request and get the pre-signed URL from the result.

QCloudGetPresignedURLRequest parameter description

Parameter Name Description Type Required
bucket Bucket name in the pre-signed request in the format <BucketName-APPID>, such as examplebucket-1250000000. It can also be viewed in the COS Console NSString* Yes
object Object in the pre-signed request. An object key (Key) is the unique ID of an object in a bucket. For example, in the object's access domain name, the object key is doc1/text.txt. For more information, please see Object Overview NSString* Yes
HTTPMethod HTTP method in the request using a pre-signed URL. Valid values (case-sensitive): @"GET", @"PUT", @"POST", @"DELETE" NSString* Yes
contentType Specifies the HTTP body encoding type for the request and response NSString* No
contentMD5 MD5 value of the file NSString* No

If needed, you can set the header or URL parameters for the request generated by the pre-signed URL in the following way:

 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;

Example of Getting 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 sample

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);

Was this page helpful?

Was this page helpful?

  • Not at all
  • Not very helpful
  • Somewhat helpful
  • Very helpful
  • Extremely helpful
Send Feedback