You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Pre-signature Mechanism
Standard Pre-signed (C++ SDK)
Copy page
Download PDF
Standard Pre-signed (C++ SDK)
By default, TosClient includes a signature in the request header when initiating a request to the server. The SDK also supports generating signed URLs, which can be used directly to initiate HTTP requests or shared with third parties to enable access authorization. This document uses uploading and downloading objects via pre-signed URLs as examples. If you have other requirements, you may refer to the settings described herein.​
Uploading Objects Using Pre-Signed URLs​
Generate a sample pre-signed URL for uploading.​
​
#include "TosClientV2.h"​
​
using namespace VolcengineTos;​
​
int main(void)​
{​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
​
std::string bucketName = "examplebucket";​
​
std::string objectName = "exampledir/exampleobject.txt";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
​
​
int64_t expires = 86400;​
​
PreSignedURLInput input(HttpMethodType::Put,bucketName,objectName,expires);​
​
// input.setAlternativeEndpoint("Your Alternative Endpoint");​
input.set​
auto output = client.preSignedURL(input);​
if(!output.isSuccess()){​
​
std::cout << "GeneratePreSignedUrl failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
std::cout << "GeneratePreSignedUrl Success, Gen Url:"<< output.result().getSignUrl() << std::endl;​
​
CloseClient();​
return 0;​
}​
​
// http://examplebucket.{endpoint/host}/exampledir/exampleobject.txt?X-Tos-Algorithm=TOS4-HMAC-SHA256&X-Tos-Credential={xxx}/{date}/{region}/tos/request&X-Tos-Date=20220922T103306Z&X-Tos-Expires=86400&X-Tos-Signature={yyy}&X-Tos-SignedHeaders=host​
​
Downloading Objects Using Pre-Signed URLs​
Generate a sample pre-signed URL for download.​
​
#include "TosClientV2.h"​
​
using namespace VolcengineTos;​
​
int main(void)​
{​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
​
std::string bucketName = "examplebucket";​
​
std::string objectName = "exampledir/exampleobject.txt";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
​
​
int64_t expires = 86400;​
​
PreSignedURLInput input(HttpMethodType::Get,bucketName,objectName,expires);​
auto output = client.preSignedURL(input);​
if(!output.isSuccess()){​
​
std::cout << "GeneratePreSignedUrl failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
std::cout << "GeneratePreSignedUrl Success, Gen Url:"<< output.result().getSignUrl() << std::endl;​
​
CloseClient();​
return 0;​
}​
​
// http://examplebucket.{endpoint/host}/exampledir/exampleobject.txt?X-Tos-Algorithm=TOS4-HMAC-SHA256&X-Tos-Credential={xxx}/{date}/{region}/tos/request&X-Tos-Date=20220922T103306Z&X-Tos-Expires=86400&X-Tos-Signature={yyy}&X-Tos-SignedHeaders=host​
​
Relevant Documentation​
For detailed information about URLs containing signatures, see URLs Containing Signatures.​
Last updated: 2025.09.25 14:22:44