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

# Attachments: Copy, Move, Rename

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.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), [Node.js](https://docs.ravendb.net/6.2/document-extensions/attachments/copying-moving-renaming.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."

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.

## Copy attachment

Attachment can be copied using one of the `session.advanced().attachments().copy` methods:

### Syntax

```java
void copy(Object sourceEntity, String sourceName,
        Object destinationEntity, String destinationName);

void copy(String sourceDocumentId, String sourceName,
        String destinationDocumentId, String destinationName);
```

### Example

```java
Employee employee1 = session.load(Employee.class, "employees/1-A");
Employee employee2 = session.load(Employee.class, "employees/2-A");

session.advanced()
  .attachments()
  .copy(employee1, "photo.jpg", employee2, "photo-copy.jpg");

session.saveChanges();
```

## Move attachment

Attachment can be moved using one of the `session.advanced().attachments().move` methods:

### Syntax

```java
void move(Object sourceEntity, String sourceName,
        Object destinationEntity, String destinationName);

void move(String sourceDocumentId, String sourceName,
        String destinationDocumentId, String destinationName);
```

### Example

```java
Employee employee1 = session.load(Employee.class, "employees/1-A");
Employee employee2 = session.load(Employee.class, "employees/2-A");

session.advanced()
  .attachments()
  .copy(employee1, "photo.jpg", employee2, "photo.jpg");

session.saveChanges();
```

## Rename attachment

Attachment can be renamed using one of the `session.advanced().attachments().rename` methods:

### Syntax

```java
void rename(Object entity, String name, String newName);

void rename(String documentId, String name, String newName);
```

### Example

```java
Employee employee1 = session.load(Employee.class, "employees/1-A");

session.advanced()
  .attachments()
  .rename(employee1, "photo.jpg", "photo-new.jpg");

session.saveChanges();
```

## See also

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