无法从一个容器复制斑点到另一个 [英] Unable to copy blobs from one container to another

查看:105
本文介绍了无法从一个容器复制斑点到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个控制台应用程序,拷贝所有容器都从斑点我们用来生产另一种我们用于开发的帐户。我有以下的方法来做到这一点。在'productionStorage'和'developmentStorage'对象是在Azure存储客户端的方式被安置另一个程序集。

I am creating a console app that copies all blobs in all containers from an account we use for production to another we use for development. I have the following method to do this. The 'productionStorage' and 'developmentStorage' objects are in another assembly where Azure storage client methods are housed.

    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)
        {
            // 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));
            }
        }
    }

我得到关于 targetBlob.StartCopyFromBlob()行错误(404)。但我不明白为什么我得到一个404错误。团块并在源(生产)存在,我想将它复制到目标(发展)。不知道我做错了。

I'm getting an error (404) on the targetBlob.StartCopyFromBlob() line. But I don't understand why I'm getting a 404 error. The blob does exist in the source (production) and I want to copy it to the destination (development). Not sure what I'm doing wrong.

推荐答案

由于源BLOB容器ACL是私人,你需要做的是建立一个SAS令牌(无论是在BLOB容器上或在该容器个别块)与许可并追加该SAS令牌blob的文件URL。请参考下面修改code:

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));
            }
        }
    }

我还没有试过运行此code,所以请原谅我,如果你遇到了这个code任何错误。但希望你的想法。

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.

这篇关于无法从一个容器复制斑点到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆