Get File URL
Updated at:2025-11-03
Users can obtain the URL of a specified object through the following code:
Plain Text
1url = client.generatePresignedUrl(bucketName, key, timestamp, expirationInSeconds, headers, params, headersToSign, config)
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 (timestamp), indicating the start time of URL validity, with a default value of the current time.expirationInSecondsis used to set the validity period of the URL, which is an optional parameter with a default value of 1,800 seconds. To set a permanent non-expiration time, theExpirationInSecondsparameter can be set to -1. You cannot set it to any other negative value.headersToSignis used to set the header list for calculation up to the preceding part
An code example is as follows:
JavaScript
1// Get access link
2let url = client.generatePresignedUrl(
3 bucketName,
4 key,
5 Math.floor(Date.now()/1000),
6 -1
7 );
8
9 // Get download link
10let donwloadUrl = client.generatePresignedUrl(
11 bucketName,
12 key,
13 Math.floor(Date.now()/1000),
14 -1,
15 {},
16 {responseContentDisposition: 'attachment'}
17 );
