Links

Rename file

put
https://api.imagekit.io
/v1/files/rename
Rename file API

Response structure and status code

In case of an error, you will get an error code along with the error message. On success, you will receive a 200 status code with the JSON-encoded response body.
The response depends upon the value of purgeCache in the request. If purgeCache is set to true, the response contains purgeRequestId, which can be used to get the purge cache status.
purgeCache=true
purgeCache=false or unset
// When purgeCache is set to true, we send the purge request ID.
// You can use this to get purge status
{
purgeRequestId: "598821f949c0a938d57563bd"
}
// When purgeCache is set to false or not set
{}

Example

Here is an example request to understand API usage.
cURL
Node.js
Python
PHP
Java
Ruby
Go
.Net
curl -X PUT "https://api.imagekit.io/v1/files/rename" \
-H 'Content-Type: application/json' \
-u your_private_key: -d '
{
"filePath" : "/path/to/old-file-name.jpg",
"newFileName" : "new-file-name.jpg",
"purgeCache": false
}
'
var ImageKit = require("imagekit");
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
imagekit.renameFile({
filePath: "/path/to/old-file-name.jpg",
newFileName: "new-file-name.jpg",
purgeCache: false // optional
}, function(error, result) {
if(error) console.log(error);
else console.log(result);
});
from imagekitio import ImageKit
imagekit = ImageKit(
public_key='your_public_api_key',
private_key='your_private_api_key',
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
)
rename_file = imagekit.rename_file(options=RenameFileRequestOptions(file_path="/file_path.jpg",
new_file_name="new_file_name.jpg",
purge_cache=True))
print("Rename file-", rename_file, end="\n\n")
# Raw Response
print(rename_file.response_metadata.raw)
# print the purge request id
print(rename_file.purge_request_id)
use ImageKit\ImageKit;
$public_key = "your_public_api_key";
$your_private_key = "your_private_api_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
$filePath='/path/to/old-file-name.jpg';
$newFileName = 'new-file-name.jpg';
$renameFile = $imageKit->rename([
'filePath' => $filePath,
'newFileName' => $newFileName,
'purgeCache' => false, // optional
]);
echo("Rename File : " . json_encode($renameFile));
RenameFileRequest renameFileRequest = new RenameFileRequest();
renameFileRequest.setFilePath("/path/to/old-file-name.jpg");
renameFileRequest.setNewFileName("new-file-name.jpg");
renameFileRequest.setPurgeCache(false);
ResultRenameFile resultRenameFile = ImageKit.getInstance().renameFile(renameFileRequest);
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
imagekitio.rename_file(
file_path: '/path/to/old-file-name.jpg',
new_file_name: 'new-file-name.jpg',
purge_cache: false #optional
)
resp, err := ik.Media.RenameFile(ctx, media.RenameFileParam{
FilePath: "/path/to/old-file-name.jpg",
NewFileName: "new-file-name.jpg",
PurgeCache: false, // Optional
})
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
RenameFileRequest renameFileRequest = new RenameFileRequest
{
filePath = "path_1",
newFileName = "file_name",
purgeCache = false
};
ResultRenameFile resultRenameFile = imagekit.RenameFile(renameFileRequest);