Can I Automatically Share Files From Object Storage Publicly?

Can I automatically share files from Object Storage publicly?

Yes this is possible with the S3 API, you can find the steps on how to set this up below. 


How do I automatically share files from Object Storage publicly?

  1. Setup your S3 tool. The easiest way is to use aws cli. Please make sure to have it installed and configured properly. 
  2. Create a file public-sharing-policy.json with the following content:
    {
    "Id": "your-fancy-name",
    "Version": "2012-10-17",
    "Statement": [
    {
    "Action": [
    "s3:GetObject"
    ],
    "Effect": "Allow",
    "Resource": [
    "arn:aws:s3:::foldername/file"
    ],
    "Principal": "*"
    }
    ]
    }


    This basically allows (Effect) reading Objects (s3:GetObject) by everyone (Principal) for the specified file (Resource).
  3. Next you need to enable public Sharing for a folder an all its sub items. To do this Create a file public-sharing-policy.json with following content:

    {
     "Id": "your-fancy-name",
     "Version": "2012-10-17",
     "Statement": [
     {
     "Action": [
     "s3:GetObject"
     ],
     "Effect": "Allow",
     "Resource": [
     "arn:aws:s3:::foldername/*"
     ],
     "Principal": "*"
     }
     ]
    }
  4. Please be aware that the S3 Object Storage doesn't support file listing in browser. The s3TenantId can be retrieved via the Contabo API.

    The only difference is that you use "*"as a wildcard / placeholder for the file name. Of course you can have constructs like "arn:aws:s3:::foldername1/foldername2/*".

How do I disable public sharing via the S3 API?

To disable the Public Sharing for a file or folder you need first to get the current policy via:


aws --profile eu2 --endpoint-url https://eu2.contabostorage.com s3api get-bucket-policy --bucket foo

Then remove the parts you would like to remove and do the put-bucket-policy again with the modified file. If it is the last entry in there you could also delete it completely via:

aws --profile eu2 --endpoint-url https://eu2.contabostorage.com s3api delete-bucket-policy --bucket foo

But be cautious as this will delete all policies on that bucket.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article

Modified on 25 Mar 2024

Can’t find what you’re looking for?

Get in Touch

Do you have a pre-sales question?