Generating a Pre-signed Link

Last updated: 2020-08-24 16:51:52

    Overview

    This document provides an overview of SDK code samples related to generating pre-signed object links.

    SDK API Reference

    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?

    Was this page helpful?

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