Hi, I have set up a Spaces and I can add files to it using laravel and S3 API package. Now I need to list my file to check if the modified date is 1 month old and then delete that file. I have tried to list object but I get:
Error executing "ListObjects" on "https://ams3.digitaloceanspaces.com/my-space%2Fbackups%2Fmy-folder?prefix=&delimiter=%2F&encoding-type=url"; AWS HTTP error: Client error: `GET https://ams3.digitaloceanspaces.com/my-space%2Fbackups%2Fmy-folder?prefix=&delim
iter=%2F&encoding-type=url` resulted in a `404 Not Found` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><BucketName>my-space</BucketName><RequestId>tx0000000 (truncated...)
NoSuchKey (client): - <?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><BucketName>my-space</BucketName><RequestId>tx0000000000000002405a5-005a5605e4-7bd0-ams3a</RequestId><HostId>7bd0-ams3a-ams3</HostId></Error>
In RequestException.php line 113:
Client error: `GET https://ams3.digitaloceanspaces.com/my-space%2Fbackups%2Fmy-folder?prefix=&delimiter=%2F&encoding-type=url` resulted in a `404 Not Found` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><BucketName>my-space</BucketName><RequestId>tx0000000 (truncated...)
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!
If you could share the code that you are using to list the files, it might help us give you a better answer. Though just from the URL of the request, I think I can hopefully point you in the right direction.
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.
To list the contents of a Space with the API, you can send a GET request to nyc3.digitaloceanspaces.com/$SPACE_NAME and it will return a the entire contents of the Space.
Your request is being sent to https://ams3.digitaloceanspaces.com/my-space/backups/my-folder instead, you should be sending /backups/my-folder/ as the “prefix” so that the response will only contain the objects with keys beginning with that string. You’re getting a 404 as the object /backups/my-folder doesn’t exist even if you have an object with a name like /backups/my-folder/file.ext
That’s a lot of detail that you might not really need. Here’s an example: If you’re using the AWS S3 SDK, it might look like:
$result = $s3Client->listObjects([
'Bucket' => 'examplebucket',
'Prefix' => '/backups/my-folder/',
]);
Hello there,
As per Andrew’s reply, the issue is with the actual URL that you’re using. I’ve had a similar issue and used something like that to get the endpoint id. To get it, just perform a curl request to list your endpoints and grab the corresponding ID from the return array:
-
- $ curl -X GET -H "Content-Type: application/json" \
- -H "Authorization: Bearer $API_TOKEN" \
- "https://api.digitalocean.com/v2/cdn/endpoints"
Regards
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.