Generating a Pre-signed Link

Last updated: 2020-08-18 10:55:30

    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.

    try {
        String bucket = "examplebucket-1250000000"; // Bucket name
        String cosPath = "exampleobject"; // Location identifier of the object in the bucket.
        String method = "PUT"; // HTTP request method
        PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(bucket
                , cosPath) {
            @Override
            public RequestBodySerializer getRequestBody()
                    throws CosXmlClientException {
                // Used to calculate a pre-signed URL for requests like `PUT` that require a request body
                return RequestBodySerializer.string("text/plain",
                        "this is test");
            }
        };
        presignedUrlRequest.setRequestMethod(method);
    
        String urlWithSign = cosXmlService.getPresignedURL(presignedUrlRequest);
    } catch (CosXmlClientException e) {
        e.printStackTrace();
    }

    Note:

    For more samples, please visit GitHub.

    try {
        String bucket = "examplebucket-1250000000"; // Bucket name
        String cosPath = "exampleobject"; // Location identifier of the object in the bucket.
        String method = "GET"; // HTTP request method
        PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(bucket
                , cosPath);
        presignedUrlRequest.setRequestMethod(method);
    
        String urlWithSign = cosXmlService.getPresignedURL(presignedUrlRequest);
    
    } catch (CosXmlClientException e) {
        e.printStackTrace();
    }

    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