I want to rename objects name from Google Cloud Bucket using C# code. How can I do that?
Asked
Active
Viewed 219 times
-1
-
1You can't change object names from external API, but you can wrap object with yours – Nehorai Elbaz Sep 21 '19 at 20:51
1 Answers
2
GCP Support here!
You can actually rename an existing object using C#. As stated in the documentation to do it you can use this code:
private void MoveObject(string bucketName, string sourceObjectName,
string destObjectName)
{
var storage = StorageClient.Create();
storage.CopyObject(bucketName, sourceObjectName, bucketName,
destObjectName);
storage.DeleteObject(bucketName, sourceObjectName);
Console.WriteLine($"Moved {sourceObjectName} to {destObjectName}.");
}
You'll see that what this code does is first copying the object with the new name, and then delete the old named object.
Here you can find more information on how to use client libraries such as for C# and other environments.

Miguel
- 956
- 6
- 20