API Create a bucket with CORS rules
API: Create a bucket with CORS-rules
Creation of a Bucket with CORS-rules
In order to create a bucket, the following API Request needs to be done:
POST /buckets/:bucketNameIn the Request-Body the following attributes can be applied:
ACL:private
public-read
public-read-write
authenticated-read
Region:eu-central-1
eu-west-1
Example (please note that in staging mode the hostname may be different):
curl -X 'POST' \
'https://mediaservice.tokenforge.tech/buckets/tokenforge-test-1' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"acl": "public-read",
"region": "eu-central-1"
}'Applying CORS:
In order to be able to upload files from your own frontend to the bucket with a pre-signed URL, a few precautions must be taken beforehand.
Let’s say, your Frontend is located at the Host berlin-marketplace.nft we have to setup a CORS rule accordingly:
POST /buckets/:bucketName/cors The request body must contain a structure that lists the HTTP methods allowed, the origins allowed, etc:
AllowedHeaders*(all headers)
AllowedMethodsPOST
PUT
GET
DELETE
OPTIONS
AllowedOrigins*(all hostnames, unsafe!)
localhost
marketplace.stage.tokenforge.tech
ExposedHeadersMaxAgeSeconds
Example (please note that in staging mode the hostname may be different):
curl -X 'PUT' \
'https://mediaservice.tokenforge.tech/buckets/tokenforge-test-1/cors' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"Rules": [
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"POST",
"GET",
"DELETE",
"PUT"
],
"AllowedOrigins": [
"berlin-marketplace.nft"
],
"ExposedHeaders": [
"Content-Length",
"Content-Type"
],
"MaxAgeSeconds": 6000
}
]
}'Warning: any subsequent call to this endpoint will overwrite existing CORS rules!
Last updated