---
title: "Put Attachment Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/attachments/put-attachment"
version: "6.2"
language: "nodejs"
---

# Put Attachment Operation

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/attachments/put-attachment.md), [Java](https://docs.ravendb.net/6.2/client-api/operations/attachments/put-attachment.java.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - Use the `PutAttachmentOperation` to add an attachment to a document.
>
> - In this page:
>
>   - [Put attachment example](#put-attachment-example)
>   - [Syntax](#syntax)

## Put attachment example

```javascript
// Prepare content to attach
const text = "Some content...";
const byteArray = Buffer.from(text);

// Define the put attachment operation
const putAttachmentOp = new PutAttachmentOperation(
  "employees/1-A", "attachmentName.txt", byteArray, "text/plain");

// Execute the operation by passing it to operations.send
const attachmentDetails = await documentStore.operations.send(putAttachmentOp);
```

## Syntax

```javascript
// Available overloads:
const putAttachmentOp = new PutAttachmentOperation(documentId, name, stream);
const putAttachmentOp = new PutAttachmentOperation(documentId, name, stream, contentType);
const putAttachmentOp = new PutAttachmentOperation(documentId, name, stream, contentType, changeVector);
```

| Parameter | Type | Description |
| - | - | - |
| **documentId** | `string` | Document ID to which the attachment will be added |
| **name** | `string` | Name of attachment to put |
| **stream** | `stream.Readable` / `Buffer` | A stream that contains the raw bytes of the attachment |
| **contentType** | `string` | Content type of attachment |
| **changeVector** | `string` | ChangeVector of attachment,<br />used for concurrency checks (`null` to skip check) |

| Return Value of `store.operations.send(putAttachmentOp)` | |
| - | - |
| `object` | An object with the new attachment's details |

```javascript
// The AttachmentDetails object:
// =============================
{
  // Change vector of attachment
  changeVector; // string

  // ID of the document that contains the attachment
  documentId?; // string

  // Name of attachment
  name; // string;

  // Hash of attachment
  hash; // string;

  // Content type of attachment
  contentType; // string

  // Size of attachment
  size; // number
}
```

## See also

- [What are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.nodejs.md)
- [Get attachment](https://docs.ravendb.net/6.2/client-api/operations/attachments/get-attachment.nodejs.md)
- [Delete attachment](https://docs.ravendb.net/6.2/client-api/operations/attachments/delete-attachment.nodejs.md)
