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

Torch Object Storage

Copy page
Download PDF
Pre-signature Mechanism
Pre-signed POST Form (C++ SDK)
Copy page
Download PDF
Pre-signed POST Form (C++ SDK)
TOS supports browser-based POST object upload requests, enabling you to upload content directly to TOS. When uploading an object using POST, you must include signature information in the form.​
Pre-signed POST form with basic parameters​
The following code is used for POST form-based pre-signed object uploads that include only basic parameters.​
​
#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;​
​
PreSignedPostSignatureInput input(bucketName,objectName, expires);​
auto output = client.preSignedPostSignature(input);​
if(!output.isSuccess()){​
​
std::cout << "GeneratePreSignedUrl failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
auto res = output.result();​
std::cout << "GeneratePreSignedUrl Success:" << "\n"​
<< "Policy: " << res.getPolicy() << "\n"​
<< "Algorithm: " << res.getAlgorithm() << "\n"​
<< "Credential: " << res.getCredential() << "\n"​
<< "Date: " << res.getDate() << "\n"​
<< "OriginPolicy: " << res.getOriginPolicy() << "\n"​
<< "Signature: " << res.getSignature() << "\n";​
​
CloseClient();​
return 0;​
​
}​
​
Pre-signed POST with multiple form fields​
The following code is an example of uploading objects with multiple form fields.​
​
#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;​
​
PreSignedPostSignatureInput input(bucketName,objectName, expires);​
​
input.setConditions(​
{PostSignatureCondition("x-tos-acl", "public-read"),​
PostSignatureCondition("key", "sdktest", std::make_shared<std::string>("starts-with"))});​
​
input.setContentLengthRange(std::make_shared<ContentLengthRange>(50, 1025));​
auto output = client.preSignedPostSignature(input);​
if(!output.isSuccess()){​
​
std::cout << "GeneratePreSignedUrl failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
auto res = output.result();​
std::cout << "GeneratePreSignedUrl Success:" << "\n"​
<< "Policy: " << res.getPolicy() << "\n"​
<< "Algorithm: " << res.getAlgorithm() << "\n"​
<< "Credential: " << res.getCredential() << "\n"​
<< "Date: " << res.getDate() << "\n"​
<< "OriginPolicy: " << res.getOriginPolicy() << "\n"​
<< "Signature: " << res.getSignature() << "\n";​
​
CloseClient();​
return 0;​
}​
​
Relevant Documentation​
For detailed information about POST form presigning, see Including a signature in browser-based upload forms.​
Last updated: 2025.09.25 14:22:44