Get file download URL
Updated at:2025-11-03
Get file download URL
Users can obtain the URL of a specified object through the following code:
Cpp
1std::string generatePresignedUrl(Client& client, const std::string& bucketName, const std::string& objectKey, int expirationInSeconds) {
2 //Specify the name of the bucket where the object that the user needs to obtain is located, the name of the object, and the valid duration of the URL
3 return client.generate_url(bucketName, objectKey, expirationInSeconds);
4}
Description:
- Before calling this function, users need to manually set the endpoint to the domain name of the corresponding region. Baidu AI Cloud currently supports multiple regions. Please refer to[Region Selection Guide](Reference/Region Selection Instructions/Region.md). Currently, the supported regions include "North China-Beijing," "South China-Guangzhou" and "East China-Suzhou." Beijing region:
http://bj.bcebos.com, Guangzhou region:http://gz.bcebos.com, Suzhou region:http://su.bcebos.com.expirationInSecondsis the specified URL validity period, calculated from the current time. It is an optional parameter, and the system default value is 1,800 seconds if not configured. To set a permanent non-expiration time, theExpirationInSecondsparameter can be set to -1. You cannot set it to any other negative value.- If the file to be obtained is expected to be publicly readable, the corresponding URL link can be quickly concatenated and obtained through simple rules:
http://$bucket.$region.bcebos.com/$object
