> ## Documentation Index
> Fetch the complete documentation index at: https://docs.antryk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Object

Upload an object (file) to Antryk Storage using a simple and optimized API.

This endpoint allows you to directly upload files to a specific bucket and path by defining them in the URL itself, making the request cleaner and more efficient.

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url "https://storage.apis.antryk.com/api/v1/buckets/:yourBucketName/objects/:yourFilePath" \
    --header "x-access-key: YOUR_ACCESS_KEY" \
    --header "x-secret-key: YOUR_SECRET_KEY" \
    --header "Content-Type: multipart/form-data" \
    --form "file=@YOUR_FILENAME"
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append("file", fileInput.files[0]);

  fetch(
    "https://storage.apis.antryk.com/api/v1/buckets/:yourBucketName/objects/:yourFilePath",
    {
      method: "POST",
      headers: {
        "x-access-key": "YOUR_ACCESS_KEY",
        "x-secret-key": "YOUR_SECRET_KEY",
      },
      body: formData,
    },
  );
  ```

  ```javascript NodeJs theme={null}
  //npm i @antryk/sdk
  import { AntrykClient } from "@antryk/sdk";
  import fs from "fs";

  const client = new AntrykClient({
    accessKey: process.env.ANTRYK_ACCESS_KEY,
    secretKey: process.env.ANTRYK_SECRET_KEY,
  });

  async function uploadFile() {
    const fileBuffer = fs.readFileSync("./po.exe");

    const result = await client.storage.upload({
      bucket: "upload-final-v1",
      key: "uploads/po.exe",
      body: fileBuffer,
      contentType: "application/octet-stream",
    });

    console.log(result.data);
  }

  uploadFile();
  ```

  ```python Python theme={null}
  # pip install requests
  import requests

  url = "https://storage.apis.antryk.com/api/v1/buckets/:yourBucketName/objects/:yourFilePath"

  headers = {
      "x-access-key": "YOUR_ACCESS_KEY",
      "x-secret-key": "YOUR_SECRET_KEY"
  }

  files = {
      "file": open("YOUR_FILENAME", "rb")
  }

  response = requests.post(url, headers=headers, files=files)

  print(response.status_code)
  print(response.json())
  ```
</CodeGroup>

<Note>
  For Node.js applications, it is recommended to use the official [`@antryk/sdk`](https://www.npmjs.com/package/@antryk/sdk).\
  The SDK abstracts authentication, request handling, and validation, allowing you to upload files using simple method calls instead of manually constructing HTTP requests.
</Note>

<Note>
  Send this request as `multipart/form-data`. Only the `file` field should be
  included in the body. All other details such as bucket name and object path
  must be provided via the URL, and authentication must be passed via
  headers.
</Note>

### New Upload Approach (Recommended)

This is the recommended and modern approach for uploading files to Antryk Storage:

* Only the `file` is sent in the request body.
* The bucket name and object path are defined directly in the URL.
* Authentication is handled via headers:
  * `x-access-key`
  * `x-secret-key`

This approach simplifies request structure, improves clarity, and aligns better with RESTful API design.

<Note>⚠️ The older approach (sending `bucket`, `key`, `accessKey`, and `secretKey` in the body) is still supported for backward compatibility, but it is **strongly recommended to migrate to this new method** for better performance, security, and maintainability.</Note>

## Request Parameters

<ParamField path="name" type="string" required>
  The name of the storage bucket. This is specified in the URL path.
</ParamField>

<ParamField path="path" type="string" required>
  The full path (including filename) where the object will be stored inside the
  bucket.
</ParamField>

<ParamField header="x-access-key" type="string" required>
  Your Antryk access key used for authentication. You can obtain this from the
  Antryk Console.
</ParamField>

<ParamField header="x-secret-key" type="string" required>
  Your Antryk secret key used for authentication. Keep this secure and never
  expose it publicly.
</ParamField>

<ParamField body="file" type="file" required>
  The file to upload. Must be sent as `multipart/form-data`.
</ParamField>

## Examples

<ParamField path="name" type="string" required>
  **Example:** `upload-final-v1`
</ParamField>

<ParamField path="path" type="string" required>
  **Example:** `uploads/po.exe`
</ParamField>

<ParamField header="x-access-key" type="string" required>
  **Example:** `YOUR_ACCESS_KEY`
</ParamField>

<ParamField header="x-secret-key" type="string" required>
  **Example:** `YOUR_SECRET_KEY`
</ParamField>

<ParamField body="file" type="file" required>
  **Example:** `YOUR_FILENAME`
</ParamField>

<Note>
  ### Additional Notes

  * Ensure the file size and type comply with your bucket configuration and limits.
  * The `path` should include the full directory structure along with the filename.
  * If a file already exists at the specified path, it may be overwritten depending on your storage settings.
  * Always keep your access credentials secure. Avoid exposing them in frontend applications.
</Note>

## Response

Returns a JSON object with upload confirmation including the object key and metadata.

```json theme={null}
{
    "success": true,
    "message": 201,
    "data": {
        "key": "tutorial/docs/todo.txt",
        "size": 215,
        "mimetype": "text/plain"
    }
}
```
