try {// Bucket nameString bucket = "examplebucket-1250000000";// Object key, the unique location ID of an object in a bucket. For more information, see [Object Key](https://www.tencentcloud.com/document/product/436/13324).// Note: The key does not need to be encoded.String cosPath = "exampleobject";// HTTP request methodString method = "PUT";PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(bucket, cosPath) {@Overridepublic RequestBodySerializer getRequestBody()throws CosXmlClientException {// Used to calculate a pre-signed URL for requests like `PUT` that require a request bodyreturn RequestBodySerializer.string("text/plain","this is test");}};presignedUrlRequest.setRequestMethod(method);// Set the signature validity period to be 60s. Note that here is the signature validity period. You need to ensure the key validity period by yourself.presignedUrlRequest.setSignKeyTime(60);// Set not to sign `Host`presignedUrlRequest.addNoSignHeader("Host");String urlWithSign = cosXmlService.getPresignedURL(presignedUrlRequest);} catch (CosXmlClientException e) {e.printStackTrace();}
try {// Bucket nameString bucket = "examplebucket-1250000000";// Object key, the unique location ID of an object in a bucket. For more information, see [Object Key](https://www.tencentcloud.com/document/product/436/13324).// Note: The key does not need to be encoded.String cosPath = "exampleobject";// HTTP request methodString method = "GET";PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(bucket, cosPath);presignedUrlRequest.setRequestMethod(method);// Set the signature validity period to be 60s. Note that here is the signature validity period. You need to ensure the key validity period by yourself.presignedUrlRequest.setSignKeyTime(60);// Set not to sign `Host`presignedUrlRequest.addNoSignHeader("Host");String urlWithSign = cosXmlService.getPresignedURL(presignedUrlRequest);} catch (CosXmlClientException e) {e.printStackTrace();}
Apakah halaman ini membantu?