Unable to copy blobs from one container to another

喜夏-厌秋 提交于 2019-12-01 08:14:09

Because the source blob container ACL is Private, what you would need to do is create a SAS Token (either on the blob container or on individual blobs in that container) with Read permission and append this SAS token to your blob's URL. Please see modified code below:

    static void CopyBlobsToDevelopment()
    {
        // Get a list of containers in production
        List<CloudBlobContainer> productionBlobContainers = productionStorage.GetContainerList();

        // For each container in production...
        foreach (var productionContainer in productionBlobContainers)
        {
            //Gaurav --> create a SAS on source blob container with "read" permission. We will just append this SAS
            var sasToken = productionContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
            {
                Permissions = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddDays(1),
            });
            // Get a list of blobs in the production container
            var blobList = productionStorage.GetBlobList(productionContainer.Name);

            // Need a referencee to the development container
            var developmentContainer = developmentStorage.GetContainer(productionContainer.Name);

            // For each blob in the production container...
            foreach (var blob in blobList)
            {
                CloudBlockBlob targetBlob = developmentContainer.GetBlockBlobReference(blob.Name);
                targetBlob.StartCopyFromBlob(new Uri(blob.Uri.AbsoluteUri + sasToken));
            }
        }
    }

I haven't tried running this code so please excuse me if you run into any errors with this code. But hopefully you get the idea.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!