---
title: "Rename file"
method: PUT
path: "/v1/files/rename"
tags: ["Digital Asset Management (DAM)", "Managing assets"]
---

# Rename file

`PUT /v1/files/rename`

You can rename an already existing file in the media library using rename file API. This operation would rename all file versions of the file. 

Note: The old URLs will stop working. The file/file version URLs cached on CDN will continue to work unless a purge is requested.

## Request body

- object
  - `filePath` string, required — The full path of the file you want to rename.
  - `newFileName` string, required — The new name of the file. A filename can contain: Alphanumeric Characters: `a-z`, `A-Z`, `0-9` (including Unicode letters, marks, and numerals in other languages). Special Characters: `.`, `_`, and `-`. Any other character, including space, will be replaced by `_`.
  - `purgeCache` boolean — Option to purge cache for the old file and its versions' URLs. When set to true, it will internally issue a purge cache request on CDN to remove cached content of old file and its versions. This purge request is counted against your monthly purge quota. Note: If the old file were accessible at `https://ik.imagekit.io/demo/old-filename.jpg`, a purge cache request would be issued against `https://ik.imagekit.io/demo/old-filename.jpg*` (with a wildcard at the end). It will remove the file and its versions' URLs and any transformations made using query parameters on this file or its versions. However, the cache for file transformations made using path parameters will persist. You can purge them using the purge API. For more details, refer to the purge API documentation. Default value - `false`

## Response `200`

On success, you will receive `purgeRequestId` in the response body, which can be used to get the purge request status. This is only sent if the `purgeCache` is set to `true` in the request. Otherwise, the response is an empty JSON.

- object
  - `purgeRequestId` string — Unique identifier of the purge request. This can be used to check the status of the purge request.

## Other responses

- `207` — In case purgeCache is set to true and total purge request count has exceeded the quota, we will rename the file but won't purge CDN cache.
- `400` — Bad request.
- `401` — Unauthorized request.
- `403` — Forbidden.
- `404` — If no file is found at the specified filePath in the media library, then a 404 response is returned.
- `409` — If a file with newFileName already exist in the same location.
- `429` — The request exceeded the rate limit. Contains headers indicating the limits and a message detailing the error.

---

[API](https://skmtc.dev/imagekit-developer/apis/imagekit-api.md) · [All operations](https://skmtc.dev/imagekit-developer/apis/imagekit-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/imagekit-developer/imagekit-api/revisions/bb3e9ff84b3e/schema)
