# Renaming Objects

<!-- -->

Tigris allows you to rename objects without rewriting the data so renames are fast and cost-effective. Because Tigris utilizes an object metadata service, renaming an object updates its metadata in place. You can rename objects in the Tigris Dashboard and via passing an additional header on the CopyObject command using your existing S3 tools.

## Renaming Objects using the Dashboard[​](#renaming-objects-using-the-dashboard "Direct link to Renaming Objects using the Dashboard")

To rename files or objects using the Tigris Dashboard, follow these steps.

Here is a step-by-step visual guide:

1. **Open the Tigris Dashboard**: Go to [Tigris Dashboard](https://console.storage.dev/) and log in.
2. **Go to the Buckets Section**: In the side navigation, click on "Buckets". Select the desired bucket and locate the file you want to rename. Click the "Rename" option from the action menu next to the file.

![Tigris File Browser](/docs/assets/images/rename-obj-step-1-2542ba7db764a01ec368d7df623a1ec4.png)

3. **Enter the New Name**: Type the new name in the provided input field. ![Tigris Rename Object Popup](/docs/assets/images/rename-obj-step-2-2d418291f75e562890aa81fa80521c79.png)

4. **Confirm the Rename**: Click "Save" to apply the new name.

5. **Verify the Change**: Check the list to ensure the object/file has been updated.

![Tigris Rename Object Success modal ](/docs/assets/images/rename-obj-step-3-52186663c3389c3a8fdd32dbc8089302.png)

## Renaming Objects using AWS SDKs[​](#renaming-objects-using-aws-sdks "Direct link to Renaming Objects using AWS SDKs")

To rename an object using AWS SDK, attach the `X-Tigris-Rename: true` header to a CopyObject request.

```
X-Tigris-Rename: true
```

This is not supported in every AWS SDK. For the languages that are not listed below, you must use the Tigris Dashboard to rename objects.

* Go
* JavaScript
* Python

```
func WithRename() func(*s3.Options) {
	return func(options *s3.Options) {
		options.APIOptions = append(options.APIOptions, http.AddHeaderValue("X-Tigris-Rename", "true"))
	}
}

// rename the object in the bucket
_, err = client.CopyObject(ctx, &s3.CopyObjectInput{
   Bucket:     aws.String(bucketName),
   CopySource: aws.String(bucketName + "/" + keyName),
   Key:        aws.String(targetName),
}, WithRename())
if err != nil {
   log.Fatalf("Unable to rename object. Here's why: %v", err)
}
```

Add the header to the S3 client middleware stack for the rename operation:

```
export const renameObject = async (S3, bucket, oldKey, newKey) => {
  S3.middlewareStack.add(
    (next) => async (args) => {
      // eslint-disable-next-line no-param-reassign
      args.request.headers["X-Tigris-Rename"] = "true";
      return next(args);
    },
    {
      step: "build",
      name: "renameObject",
      tags: ["METADATA", "RENAME"],
    },
  );

  const copyCommand = new CopyObjectCommand({
    Bucket: bucket,
    CopySource: `${bucket}/${oldKey}`,
    Key: newKey,
  });

  await S3.send(copyCommand);

  S3.middlewareStack.remove("renameObject");
};

const S3 = new S3Client({
  region: "auto",
  s3ForcePathStyle: false,
  endpoint: "https://t3.storage.dev",
});

console.log("Rename object");
await renameObject(S3, bucket, object, newObject);
```

Create a dedicated boto3 client for the rename operation, otherwise every copy\_object call will become a rename operation.

```
svc = boto3.client(
    's3',
    endpoint_url='https://t3.storage.dev',
    config=Config(s3={'addressing_style': 'virtual'}),
)

def _x_tigris_rename(request):
    request.headers.add_header('X-Tigris-Rename', "true")

# Register event into boto
svc.meta.events.register(
    "before-sign.s3.CopyObject",
    lambda request, **kwargs: _x_tigris_rename(request),
)

# Rename object
response = svc.copy_object(
    Bucket='tigris-example',
    CopySource='tigris-example/source-object.txt',
    Key='renamed-object.txt',
)
```
