Azure Blob REST API does not dirrectly support Move/Rename operation. You need to create a new blob container with the new name and copy blobs from old blob container to the new one. Once the blobs are copied, you can delete the old blob container.
Copy blob in Cloud operation is asynchronous, ensure that the blobs are copied completely before deleting the blob container.
In your case the StartCopyFromUriAsync
operation is the only way to move the file from one location in my blob container to another.
Example:
async function renameBlob(containerClient, existingName, newName) {
// assume blob exists and names are different
const blobClient = containerClient.getBlobClient(existingName);
const newBlobClient = containerClient.getBlobClient(newName);
const poller = await newBlobClient.beginCopyFromURL(blobClient.url);
await poller.pollUntilDone();
/* test code to ensure that blob and its properties/metadata are copied over
const prop1 = await blobClient.getProperties();
const prop2 = await newBlobClient.getProperties();
if (prop1.contentLength !== prop2.contentLength) {
throw new Error("Expecting same size between copy source and destination");
}
if (prop1.contentEncoding !== prop2.contentEncoding) {
throw new Error("Expecting same content encoding between copy source and destination");
}
if (prop1.metadata.keya !== prop2.metadata.keya) {
throw new Error("Expecting same metadata between copy source and destination");
}
*/
await blobClient.delete();
return newBlobClient;
}
https://learn.microsoft.com/en-us/rest/api/storageservices/blob-service-rest-api
Official information from Microsoft: Azure Blob Move/Rename operation
https://github.com/Azure/azure-sdk-for-js/issues/7202