How Do I Obtain an Object URL?
If an object in a bucket can be read by anonymous users, anonymous users can download the object through the object URL. Methods to obtain the object URL are as follows:
Method 1: Query by calling the API. After an object is uploaded by calling ObsClient.putContent or ObsClient.putFile, PutContentResponse is returned. You can call objectUrl to obtain the URL of the uploaded object. Sample code is as follows:
# Import the module.
from obs import ObsClient
# Create an instance of ObsClient.
obsClient = ObsClient(
access_key_id='*** Provide your Access Key ***',
secret_access_key='*** Provide your Secret Key ***',
server='https://your-endpoint'
)
resp = obsClient.putContent('bucketname', 'objectname', content='Hello OBS')
if resp.status < 300:
print('requestId:', resp.requestId)
print('objectUrl:', resp.body.objectUrl)
else:
print('requestId:', resp.requestId)
print('errorCode:', resp.errorCode)
Method 2: Compose the URL in the format of https://Bucket name.Domain name/Directory level/Object name.
- If the object resides in the root directory of a bucket, its URL does not contain a directory level.
- You can click here to view the domain names of each region.
- For example, if you want to access the object named test.txt in the test folder of bucket testbucket residing in region CN North-Beijing4, the URL of the object is https://testbucket.obs.cn-north-4.myhuaweicloud.com/test/test.txt.
Last Article: What Is the Retry Mechanism of SDK?
Next Article: How Do I Improve the Uploading Speed of Large Files over the Public Network?
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.