# How to upload an object to an Object Storage bucket

This guide walks you through uploading an object to an Object Storage bucket using the [Azion Console](https://console.azion.com/object-storage), [Azion API](https://api.azion.com/), [Azion CLI](/en/documentation/products/azion-cli/overview/), and [Azion Runtime](/en/documentation/runtime/api-reference/storage/).

import Tabs from '~/components/tabs/Tabs'
import DocButton from '~/components/webkit/DocButton.vue';

## Uploading an object to a bucket

<Tabs client:visible>
    <Fragment slot="tab.console">Console</Fragment>
    <Fragment slot="tab.cli">Azion CLI</Fragment>
    <Fragment slot="tab.runtime">Azion Runtime</Fragment>
    <Fragment slot="tab.api">API</Fragment>

<Fragment slot="panel.console">

In the Azion [Console](https://console.azion.com/object-storage), you can upload files to a bucket by following these steps:

1. Access the **Object Storage** menu in the Products menu.
2. On the Object Storage page, click on the bucket you want to update.
3. Drag files to add them to your bucket or click the "Add to files" button.

![Add files to bucket](/assets/docs/images/uploads/storage-add-files-to-bucket-console.png)

</Fragment>

<Fragment slot="panel.cli">

## Requirements 

- [Azion CLI installed](/en/documentation/products/azion-cli/overview/#installing-azion-cli). 
- [A personal token configured](/en/documentation/devtools/cli/globals/#token).

To upload an object to an Object Storage bucket: 

```bash 
azion create edge-storage object --bucket-name bucketname  --source pathtoyourfile --object-key objectname
```

</Fragment>

<Fragment slot="panel.api">

To upload an object, run the following `POST` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/), `<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:

```bash
curl --location 'https://api.azion.com/v4/storage/buckets/<bucket_name>/objects/<object_key>' \
--header 'Accept: application/json;' \
--header 'Content-Type: text/csv' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '@./path/file.csv'
```

You should receive the following response:

```json
{
    "state": "executed",
    "data": {
        "object_key": "folder/csv-file"
    }
}
```

</Fragment>

<Fragment slot="panel.runtime">

You can create a 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:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Functions**.
2. Click the **+ Function** button.
3. Name your function. Example: `my-bucket POST`.
4. In the **Code** tab, add the following JavaScript code:

```js
import Storage from "azion:storage";

async function handleRequest(event) {
    try{
        const bucket = “mybucket”
        const storage = new Storage(bucket);
        const key = "test";
        const inputStream = event.request.body;
        let contentLength = event.request.headers.get("content-length");
        await storage.put(key, inputStream, { "content-length": contentLength });
        return new Response("OK");
    }catch(error){
        return new Response(error, {status:500});
    }
}

addEventListener("fetch", (event) => {
    event.respondWith(handleRequest(event));
});
```


:::note 
Remember to replace "mybucket" with your bucket's name and "test" with the object key.
:::

5. Click the **Save** button.

:::note
See the [Object Storage API](/en/documentation/runtime/api-reference/storage/) reference for more details on functions available for other types of requests.
:::

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

<DocButton href="/en/documentation/products/build/applications/first-steps/" label="Go to Applications first steps" kind="secondary" target="_blank" size="medium" />
<DocButton href="/en/documentation/products/guides/build/instantiate-functions/" label="Go to how to instantiate an function" kind="secondary" target="_blank" size="medium" />

</Fragment>
</Tabs>