How to upload and download objects from an Edge Storage bucket
Azion Edge Storage allows you to create buckets and integrate your object storage with your edge infrastructure. This guide covers how to upload and download objects from a bucket using the Azion API and Azion Runtime.
Go to Edge Storage referenceRead How to create and modify an Edge Storage bucket for bucket operations.
Via API
Uploading an object to a bucket
To upload an object, run the following POST
request in your terminal, replacing [TOKEN VALUE]
with your personal token, <bucket_name>
with the name of your bucket, <object_key>
with an ID or name for the object, the Content-Type
header with the MIME type being submitted, and the object sent as a data binary:
You should receive the following response:
Downloading an object from a bucket
To download the object, run the following GET
request in your terminal, replacing [TOKEN VALUE]
with your personal token, <bucket_name>
with the name of your bucket, and <object_key>
with the key created for the object:
You should now see the contents of the object in your terminal.
Via Azion Runtime
You can create an edge function to upload objects to your bucket using a POST
console command and see if an object is available using a GET
console command. To do so:
- Access Azion Console > Edge Functions.
- Click the Add Function button.
- Name your function. Example:
my-bucket POST+GET
. - In the Code tab, add the following JavaScript code:
Variable | Description |
---|---|
path | Path to the object. Example: ./path/file.csv |
bucket_name | The name of the bucket. Example: my-bucket |
content_type | The MIME type of the object. Example: text/csv |
value | The contents of the object as a data binary |
- In the Arguments tab, add the object with the
bucket
property and, as a value, the name of the bucket as a string.
- Click the Save button.
Once you have the edge function ready, you need to create an edge application that will proxy the upload process for the bucket.
- Access Azion Console.
- Select the Start with a template option on the homepage.
- Select the Build from scratch option.
- Give your application an easy-to-remember name. Example:
my-bucket Proxy
. - Select the option Run a Function.
- In Choose Edge Function, select the edge function you created in the previous steps.
- Click the Next button.
- Copy the link of the edge application. It should be in the format
http://xxxxxxxxxx.map.azionedge.net
. - Run the following command in your terminal to upload an object:
- Run the following command in your terminal to download an object: