Get file download URL
Updated at:2025-11-03
Users can obtain the URL of a specified object through the following code:
Plain Text
1url = bos_client.generate_pre_signed_url(bucket_name, object_key, timestamp, expiration_in_seconds)
Description:
- Before calling this function, users need to manually set the
endpointto 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.timestampis an optional parameter. If not configured, it defaults to the current time.timestampis a timestamp that identifies the start time of URL validity,timestamp=int(time.time()), and* import timeis required.expriation_in_secondsis used to set the validity period of the URL, which is an optional parameter and defaults to 1,800 seconds if not it is configured. To set a permanent non-expiration time, theExpirationInSecondsparameter can be set to -1. You cannot set it to any other negative value.
It now supports getting through the STS method. For configuring STS to access BOS, see the initialization page. The code example is as follows:
Python
1# Import the STS configuration file
2import sts_sample
3import time
4# create a sts bos client
5sts_bos_client = BosClient(sts_sample.config)
6timestamp =int(time.time())
7url = sts_bos_client.generate_pre_signed_url(bucket_name, key, timestamp,
8 expiration_in_seconds=3600)
