简体   繁体   中英

Get openstack public url of an object

I am using openstack to upload an object to a container like explained here: https://docs.openstack.org/openstacksdk/latest//user/guides/object_store.html#uploading-objects

I would like to know if it is possible to programmatically know the public url of the file that I just uploaded.

I am using the python openstack sdk framework but I cannot find a method to have this with any of the endpoints that are available there.

The Object Storage API supports the standard, non-serialized response format, which is the default, and both JSON and XML serialized response formats.I you are authorized, you can get it like:

/v1/{account}/{container}/{object}
/v1/12345678912345/my_files/mypicture01.jpg

For example, if the endpoint for Object Storage is objects.mycloud.com, the returned URL is "https://objects.openstackmycloud.com/v1/12345678912345/my_files".

To access a container, append the container name to the resource path.

To access an object, append the container and the object name to the path.

I guess openstack using swift for object store, in that case you can use the swift python client:

https://docs.openstack.org/python-swiftclient/latest/service-api.html

The endpoint is defined in your openstack and you can list the endpoints with

openstack endpoint list

This isn't directly related to programmatic access in Python, but for future google searchers, here are two methods I've found:

Via GUI

Go to Object Store -> Containers in the OpenStack dashboard, then click on your container. If you check "Public Access", then the following link will appear: 在此处输入图像描述

Via CLI

You have to have python-swiftclient installed and the appropriate credentials configured:

  1. Run swift stat <container> . If the output includes Read ACL: .r:* then it has public access, so you're all good. If not, use swift post --read-acl.r:* <container>
  2. Get the swift base URL using swift auth . It will output something like OS_STORAGE_URL=https://object-store.some.host/v1/AUTH_06d6e708e3e642da99d846ba3ea629c5 . This URL is the base URL you will use to calculate the public URL.
  3. The final public URL will be {base}/{container}/{object} , eg for an object called object.txt in container container , the URL would be https://object-store.some.host/v1/AUTH_06d6e708e3e642da99d846ba3ea629c5/container/object.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM