---
title: "Attachments: Copy, Move, Rename"
url: "https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming"
version: "6.2"
language: "nodejs"
---

# Attachments: Copy, Move, Rename

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.md), [Java](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.java.md), [Python](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.python.md), [PHP](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.php.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**
>
> - Attachments can be copied, moved, or renamed using built-in session methods.
>
> - All of those actions are executed when `saveChanges` is called and take place on the server-side,  
>   removing the need to transfer the entire attachment binary data over the network in order to perform the action.
>
> - In this page:
>   - [Copy attachment](#copy-attachment)
>   - [Move attachment](#move-attachment)
>   - [Rename attachment](#rename-attachment)
>   - [Syntax](#syntax)

## Copy attachment

Use `session.advanced.attachments.copy` to copy an attachment from one document to another.

### Copy\_with\_entity

```javascript
// Load entities
const employee1 = await session.load("employees/1-A");
const employee2 = await session.load("employees/2-A");

// Call method 'copy'
// Copy attachment from employee1 to employee2
session.advanced.attachments.copy(employee1, "photo.jpg", employee2, "photo-copy.jpg");

// Attachment will be copied on the server-side only when saveChanges is called
await session.saveChanges();
```

### Copy\_with\_document\_ID

```javascript
// Call method 'copy'
// Copy attachment from "employees/1-A" to "employees/2-A"
session.advanced.attachments.copy("employees/1-A", "photo.jpg", "employees/2-A", "photo-copy.jpg");

// Attachment will be copied on the server-side only when saveChanges is called
await session.saveChanges();
```

## Move attachment

Use `session.advanced.attachments.move` to move an attachment from one document to another.

### Move\_with\_entity

```javascript
// Load entities 
const employee1 = await session.load("employees/1-A");
const employee2 = await session.load("employees/2-A");

// Call method 'move'
// Move attachment from employee1 to employee2
session.advanced.attachments.move(employee1, "photo.jpg", employee2, "photo.jpg");

// Attachment will be moved on the server-side only when saveChanges is called
await session.saveChanges();
```

### Move\_with\_document\_ID

```javascript
// Call method 'move'
// Move attachment from "employees/1-A" to "employees/2-A"
session.advanced.attachments.move("employees/1-A", "photo.jpg", "employees/2-A", "photo.jpg");

// Attachment will be moved on the server-side only when saveChanges is called
await session.saveChanges();
```

## Rename attachment

Use `session.advanced.attachments.rename` to rename an attachment.

### Rename\_with\_entity

```javascript
// Load entity
const employee = await session.load("employees/1-A");

// Call method 'rename'
// Rename "photo.jpg"
session.advanced.attachments.rename(employee, "photo.jpg", "photo-new.jpg");

// Attachment will be renamed on the server-side only when saveChanges is called
await session.saveChanges();
```

### Rename\_with\_document\_ID

```javascript
// Call method 'rename'
// Rename "photo.jpg"
session.advanced.attachments.rename("employees/1-A", "photo.jpg", "photo-new.jpg");

// Attachment will be renamed on the server-side only when saveChanges is called
await session.saveChanges();
```

## Syntax

```javascript
// Copy - available overloads:
// ===========================
copy(sourceEntity, sourceName, destinationEntity, destinationName);
copy(sourceDocumentId, sourceName, destinationDocumentId, destinationName);
```

```javascript
// Move - a vailable overloads:
// ============================
move(sourceEntity, sourceName, destinationEntity, destinationName);
move(sourceDocumentId, sourceName, destinationDocumentId, destinationName);
```

| Parameter | Type | Description |
| - | - | - |
| **sourceEntity** | `object` | Source entity |
| **destinationEntity** | `object` | Destination entity |
| **sourceDocumentId** | string | Source document Id |
| **destinationDocumentId** | string | Destination document Id |
| **sourceName** | string | Source attachment name |
| **destinationName** | string | Destination attachment name |

```javascript
// Rename - available overloads:
// =============================
rename(entity, name, newName);
rename(documentId, name, newName);
```

| Parameter | Type | Description |
| - | - | - |
| **entity** | `object` | The document entity |
| **documentId** | string | The document Id |
| **name** | string | Current name of attachment |
| **newName** | string | The new name for the attachment |

## See also

- [What are Attachments](https://docs.ravendb.net/6.2/document-extensions/attachments/what-are-attachments.nodejs.md)
- [Storing](https://docs.ravendb.net/6.2/document-extensions/attachments/storing.nodejs.md)
- [Loading](https://docs.ravendb.net/6.2/document-extensions/attachments/loading.nodejs.md)
- [Deleting](https://docs.ravendb.net/6.2/document-extensions/attachments/deleting.nodejs.md)
