# How to update an object from an Object Storage bucket

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

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

## Updating an object from a bucket

<Tabs client:visible>
    <Fragment slot="tab.cli">CLI</Fragment>
    <Fragment slot="tab.runtime">Azion Runtime</Fragment>
    <Fragment slot="tab.api">API</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 update a bucket: 

```bash 
azion update edge-storage object 
```

Azion CLI will present a series of interactions, so the object can be updated. Run `azion update edge-storage bucket -h` for further information about the data that can be updated. 

</Fragment >

<Fragment slot="panel.api">

Run the following `PUT` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/products/guides/personal-tokens/), `<bucket_name>` with the name of the bucket, `<object_key>` with the key of the object, and `path/file.src` with the path to your new file:

<Code lang="bash" code={`
curl --location --request PUT 'https://api.azion.com/v4/storage/buckets/<bucket_name>/objects/<object_key>' \
--header 'Accept: application/json' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/octet-stream' \
--data '@'
`} />

You should receive a response similar to this:

```json
{
  "state": "executed",
  "data": {
    "object_key": "people-100.txt"
  }
}
```

</Fragment>

<Fragment slot="panel.runtime">

You can create an function to update an object from your bucket. 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: `object-update`.
4. In the **Code** tab, add the following JavaScript code, passing your bucket's name and the object key:

```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 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>