How to download an object from an Object Storage bucket

This guide walks you through downloading an object from an Object Storage bucket using the Azion API and Azion Runtime.

Downloading an object from a bucket

You can create an function to download objects from your bucket using a GET console command. To do so:

  1. Access Azion Console > Functions.
  2. Click the + Function button.
  3. Name your function. Example: my-bucket GET.
  4. In the Code tab, add the following JavaScript code, passing your bucket’s name and the object key:
import Storage from "azion:storage";
async function handleRequest(event) {
try{
const bucket = "mybucket";
const storage = new Storage(bucket);
const key = "test";
const storageObject = await storage.get(key);
return new Response(storageObject.content);
}catch(error){
return new Response(error, {status:500});
}
}
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event));
});
  1. Click the Save button.

Once you have the function ready, you need to create an applications that will proxy the process for the bucket and instantiate the function.

Go to Applications first stepsGo to how to instantiate an function