Docs · Object storage

Upload from the browser (CORS).

Your page sends a file straight to the bucket; your server only signs the URL. Without a CORS rule the browser blocks the upload before it starts.

A browser only lets a page on https://app.example.com send a request to https://s3.computeforge.com if the bucket says that origin may. You say so with a CORS rule on the bucket. The upload itself is signed by your server, so your access key never reaches the browser.

The examples use the AWS CLI profile the panel gives you when you create an access key (Object storage → Access keys → New key), so every command carries --profile computeforge --endpoint-url https://s3.computeforge.com. Any S3 client works the same way.

1. Allow your site to upload

Save this as cors.json, with your own site's address:

{
  "CORSRules": [
    {
      "AllowedOrigins": ["https://app.example.com"],
      "AllowedMethods": ["PUT", "GET", "HEAD"],
      "AllowedHeaders": ["content-type"],
      "ExposeHeaders": ["ETag"],
      "MaxAgeSeconds": 3000
    }
  ]
}
aws s3api put-bucket-cors --bucket my-uploads \
  --cors-configuration file://cors.json \
  --profile computeforge --endpoint-url https://s3.computeforge.com
  • AllowedOrigins: the exact address of your site (scheme, host and port). One * is allowed per entry (https://*.example.com). An origin of * alone allows every site, without cookies or credentials.
  • AllowedMethods: any of GET, PUT, POST, DELETE, HEAD.
  • AllowedHeaders: the request headers your page sends. One * per entry is allowed.
  • ExposeHeaders: response headers your script may read. ETag is needed for multipart uploads.
  • A bucket may have up to 100 rules. The first rule that matches the origin and method applies.

A CORS rule does not make anything public. It only tells the browser which pages may make requests to the bucket. Every request still needs a signature, except the browser's own preflight check (OPTIONS) and, in a bucket made public in the panel, downloads of its current files.

2. Sign an upload URL on your server

A presigned URL lets the browser upload one object, for as long as you choose (at most 7 days):

import boto3
from botocore.config import Config

s3 = boto3.client(
    "s3", endpoint_url="https://s3.computeforge.com",
    aws_access_key_id=ACCESS_KEY,
    aws_secret_access_key=SECRET_KEY,
    region_name=REGION,  # the region shown on the Object storage page
    config=Config(signature_version="s3v4",
                  s3={"addressing_style": "path"}))

url = s3.generate_presigned_url(
    "put_object", ExpiresIn=600,
    Params={"Bucket": "my-uploads", "Key": "avatars/42.png",
            "ContentType": "image/png"})

Set signature_version="s3v4": the endpoint accepts Signature Version 4 only, and some SDK versions presign with the older version unless told; such a URL is refused with 403. The AWS CLI profile from the panel already sets it. With a profile of your own on AWS CLI version 1, set it once before aws s3 presign: aws configure set s3.signature_version s3v4 --profile <your profile>.

3. Upload from the page

await fetch(url, {
  method: "PUT",
  body: file,
  headers: { "Content-Type": "image/png" },
});

Send the same Content-Type you signed. For large files, use a multipart upload: your server starts it and presigns one URL per part; the page uploads the parts and reads each part's ETag (that is why the rule exposes it); your server completes the upload.

HTML form uploads (POST with an upload policy) are not supported. Use a presigned PUT as above.

Check the rule

curl -i -X OPTIONS https://s3.computeforge.com/my-uploads/test.txt \
  -H "Origin: https://app.example.com" \
  -H "Access-Control-Request-Method: PUT" \
  -H "Access-Control-Request-Headers: content-type"

A 200 with Access-Control-Allow-Origin means the browser may upload. A 403 means no rule matches that origin, method or header.

Read the rules back with aws s3api get-bucket-cors, and remove them with aws s3api delete-bucket-cors. A read-only key can read the rules; changing them needs a read-and-write key granted the bucket.

More on object storage