我正在使用@azure/storage-blob包来操作Azure中的文件。
在同一个Azure存储帐户中,我有两个存储容器,即源和目的地。
我尝试做的是将位于源容器中的文件复制到目标容器,而无需下载该文件。
我正在下载到缓冲区并上传到目的地。
有没有办法直接做到这一点?
const blobServiceClient = BlobServiceClient.fromConnectionString(BLOB_CONNECTION_STRING);
const sourceContainerClient = blobServiceClient.getContainerClient(SOURCE_CONTAINER_NAME);
const sourceBlockBlobClient = sourceContainerClient.getBlockBlobClient(filename);
const destinationContainerClient = blobServiceClient.getContainerClient(DESTINATION_CONTAINER_NAME);
const destinationBlockBlobClient = finalContainerClient.getBlockBlobClient(filename);
const sourceFileBuffer = await sourceBlockBlobClient.downloadToBuffer();
destinationBlockBlobClient.uploadData(sourceFileBuffer);
字符串
1条答案
按热度按时间ygya80vv1#
在Azure Blob容器之间复制文件。
您可以使用下面的代码使用JavaScript SDK将文件从一个容器复制到另一个容器。
验证码:
字符串
输出:
型
的数据
门户:
参考号:
Get started with Azure Blob Storage and JavaScript - Azure Storage | Microsoft Learn