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
To rename files or objects using the Tigris console, follow these steps.
Here is a step-by-step visual guide:
- Open the Tigris Console: Go to Tigris Console and log in.
- 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.
-
Enter the New Name: Type the new name in the provided input field.
-
Confirm the Rename: Click "Save" to apply the new name.
-
Verify the Change: Check the list to ensure the object/file has been updated.
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 console 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://fly.storage.tigris.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://fly.storage.tigris.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',
)