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

# Put Attachment Operation

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/attachments/put-attachment.md), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/attachments/put-attachment.nodejs.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."

This operation is used to put an attachment to a document.

## Syntax

```java
PutAttachmentOperation(String documentId, String name, InputStream stream)

PutAttachmentOperation(String documentId, String name, InputStream stream, String contentType)

PutAttachmentOperation(String documentId, String name, InputStream stream, String contentType, String changeVector)
```

```java
public class AttachmentDetails extends AttachmentName {
  private String changeVector;
  private String documentId;

  public String getChangeVector() {
      return changeVector;
  }

  public void setChangeVector(String changeVector) {
      this.changeVector = changeVector;
  }

  public String getDocumentId() {
      return documentId;
  }

  public void setDocumentId(String documentId) {
      this.documentId = documentId;
  }
}

public class AttachmentName {
  private String name;
  private String hash;
  private String contentType;
  private long size;

  public String getName() {
      return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public String getHash() {
      return hash;
  }

  public void setHash(String hash) {
      this.hash = hash;
  }

  public String getContentType() {
      return contentType;
  }

  public void setContentType(String contentType) {
      this.contentType = contentType;
  }

  public long getSize() {
      return size;
  }

  public void setSize(long size) {
      this.size = size;
  }
}
```

| Parameter | | |
| - | - | - |
| **documentId** | String | ID of a document which will contain an attachment |
| **name** | String | Name of an attachment |
| **stream** | InputStream | Stream contains attachment raw bytes |
| **contentType** | String | MIME type of attachment |
| **changeVector** | String | Entity changeVector, used for concurrency checks (`null` to skip check) |

| Return Value | |
| - | - |
| **ChangeVector** | Change vector of created attachment |
| **DocumentId** | ID of document |
| **Name** | Name of created attachment |
| **Hash** | Hash of created attachment |
| **ContentType** | MIME content type of attachment |
| **Size** | Size of attachment |

## Example

```java
AttachmentDetails attachmentDetails = store
  .operations().send(new PutAttachmentOperation("orders/1-A",
      "invoice.pdf",
      stream,
      "application/pdf"));
```

## See also

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