> For the complete documentation index, see [llms.txt](https://bittu-1.gitbook.io/meshkit-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bittu-1.gitbook.io/meshkit-documentation/api/upload.md).

# upload()

## Overview

Uploads a `Blob` or `File` to IPFS using Pinata and returns a MeshKit record containing the resulting CID.

## Purpose

Use `upload()` for binary file content such as documents, exports, images, or generated blobs.

## Endpoint / Method

```ts
async upload(
  file: Blob | File,
  options?: StoreOptions
): Promise<MeshkitRecord<void>>
```

Provider endpoint:

```http
POST https://api.pinata.cloud/pinning/pinFileToIPFS
```

## Parameters

| Name              | Type           | Required | Description                                                                     |
| ----------------- | -------------- | -------- | ------------------------------------------------------------------------------- |
| `file`            | `Blob \| File` | Yes      | Binary content to upload.                                                       |
| `options`         | `StoreOptions` | No       | Accepted by the signature. Current implementation does not apply these options. |
| `options.encrypt` | `boolean`      | No       | Reserved. Not currently applied.                                                |
| `options.label`   | `string`       | No       | Reserved. Not currently applied.                                                |

### Request schema table

| Field             | Type           | Required | Notes                                     |
| ----------------- | -------------- | -------- | ----------------------------------------- |
| `file`            | `Blob \| File` | Yes      | Added to `FormData` under the `file` key. |
| `options.encrypt` | `boolean`      | No       | Accepted by type; not implemented.        |
| `options.label`   | `string`       | No       | Accepted by type; not implemented.        |

## Response

Returns `Promise<MeshkitRecord<void>>`.

```ts
{
  cid: string;
  timestamp: number;
  data: undefined;
  size: number;
}
```

| Field       | Description                                     |
| ----------- | ----------------------------------------------- |
| `cid`       | IPFS CID returned by Pinata as `IpfsHash`.      |
| `timestamp` | Client-side `Date.now()` value in milliseconds. |
| `data`      | Always `undefined` for file uploads.            |
| `size`      | `file.size` in bytes.                           |

### Response schema table

| Field       | Type        | Description                               |
| ----------- | ----------- | ----------------------------------------- |
| `cid`       | `string`    | CID returned by `provider.putFile(file)`. |
| `timestamp` | `number`    | `Date.now()` when the record is created.  |
| `data`      | `undefined` | The method returns `MeshkitRecord<void>`. |
| `size`      | `number`    | `file.size` in bytes.                     |

## Examples

### Example request

```ts
const file = new File(["hello"], "hello.txt", {
  type: "text/plain",
});

const record = await meshkit.upload(file);
```

### Example response

```ts
{
  cid: "bafybeifileexamplecid",
  timestamp: 1760000000000,
  data: undefined,
  size: 5,
}
```

## Errors

| Error                  | Cause                           |
| ---------------------- | ------------------------------- |
| Provider error details | Pinata rejected the upload.     |
| `HTTP error 401`       | Invalid Pinata JWT.             |
| Network error          | Runtime could not reach Pinata. |

### Error schema table

| Field     | Type     | Description                                                            |
| --------- | -------- | ---------------------------------------------------------------------- |
| `name`    | `string` | Standard JavaScript error name.                                        |
| `message` | `string` | Pinata error details, `HTTP error {status}`, or network error message. |

## Notes

* If the value is a `File`, its `name` is sent to Pinata.
* If the value is a `Blob`, MeshKit uses `meshkit-file` as the upload filename.
* The current implementation does not attach custom metadata from `options.label`.

## Best Practices

* Use `store()` for JSON data and `upload()` for binary content.
* Keep the returned CID with any application metadata needed to identify the file later.
* Consider file size limits and upload progress needs in the host application.

## Related APIs

* [download()](/meshkit-documentation/api/download.md)
* [store()](/meshkit-documentation/api/store.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bittu-1.gitbook.io/meshkit-documentation/api/upload.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
