By Taha
I have created a space and then the folder inside the space to store mp3 files. I would like to access all the files stored in the folder programaticallty. Is there any index.html file created for every folder content? Or How would I access the files stored in the folder?
I have tried https://spacename.nyc3.digitaloceanspaces.com/, which list all the files and folders (permission is set to Public)
But when is there some URL, https://spacename.nyc3.digitaloceanspaces.com/folder-name/ to access the files inside the particular folder?
Thanks.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
In order to be compatible with existing tools, the Spaces API was designed to be inter-operable with the S3 API. With S3, there is no real concept of a folder. When you create a “folder” through the Spaces UI, it is actually just a “key” with a zero sized “object.” Items inside the folder have the folder key as a prefix to their own key.
For example, here is a listing of objects in a Space with a folder named foo containing a file named bar using the aws cli:
$ aws s3api --endpoint-url https://nyc3.digitaloceanspaces.com --profile do list-objects --bucket my-bucket
{
"Contents": [
{
"LastModified": "2017-10-17T17:50:50.840Z",
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
"StorageClass": "STANDARD",
"Key": "foo/",
"Owner": {
"DisplayName": "681451698",
"ID": "681451698"
},
"Size": 0
},
{
"LastModified": "2017-10-17T17:56:08.583Z",
"ETag": "\"8cf8463b34caa8ac871a52d5dd7ad1ef\"",
"StorageClass": "STANDARD",
"Key": "foo/bar",
"Owner": {
"DisplayName": "681451698",
"ID": "681451698"
},
"Size": 2
}
]
}
You can programmatically list the contents of a “folder” by including a prefix query parameter when calling the API to list the contents of a Space. Here’s a quick Python 3 example:
import boto3
session = boto3.session.Session()
client = session.client('s3',
region_name='nyc3',
endpoint_url='https://nyc3.digitaloceanspaces.com',
aws_access_key_id='ACCESSKEY',
aws_secret_access_key='SECRETKEY')
resp = client.list_objects(Bucket='my-bucket', Prefix='foo/')
for obj in resp['Contents']:
print(obj['Key'])
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.