Azure StartCopyBlob仅由Uri复制?

时间:2017-04-23 00:55:41

标签: c# azure azure-storage azure-storage-blobs

我正在编写一些代码来复制另一个blob并使用另一个项目中的一些代码作为模板。但我的新项目中的blob.StartCopy只需要一个URI。在我的另一个项目中,StartCopy方法有3个重载,一个带有blob,这就是我想要做的。所以我想我没有引用我应该做的事情?

Refence                                                      Old       New
Microsoft.Azure.Storage                                      5.0.2.0   8.1.1.0
Microsoft.WindowsAzure.MediaServices.Common.Blob.Transfer    3.8.0.5   3.8.0.5

这是代码......

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(  CloudConfigurationManager.GetSetting("StorageConnectionString"));
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(_avStorageContainerName);
        container.CreateIfNotExists();
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(imageName);
        using (var fileStream = System.IO.File.OpenRead(testFileName))
            blockBlob.UploadFromStream(fileStream);
        IAsset asset = _context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.None);
        IAccessPolicy writePolicy = _context.AccessPolicies.Create("writePolicy", TimeSpan.FromDays(30), AccessPermissions.Write);
        var newGuid = Guid.NewGuid();
                 ILocator destinationLocator = _context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy)
        Uri uploadUri = new Uri(destinationLocator.Path);
        var assetContainerName = uploadUri.Segments[1];
        CloudBlobContainer assetContainer = blobClient.GetContainerReference(assetContainerName);
        var mediaBlobContainer = blobClient.GetContainerReference(_avStorageContainerName);
        mediaBlobContainer.CreateIfNotExists();
        var sourceCloudBlob = mediaBlobContainer.GetBlockBlobReference(imageName);
        sourceCloudBlob.FetchAttributes();
        IAssetFile assetFile = asset.AssetFiles.Create(imageName);
        var destinationBlob = container.GetBlobReference(imageName);
        if (destinationBlob.Exists())
             destinationBlob.DeleteIfExists();
        destinationBlob.StartCopy(sourceCloudBlob);
  

这是我的参考文献的副本。它们都是NuGet的最新产品。   也许我错过了什么?

enter image description here

1 个答案:

答案 0 :(得分:1)

我想我知道为什么会这样。问题在于以下代码行:

var destinationBlob = container.GetBlobReference(imageName);

基本上你在这里创建一个CloudBlob类型的实例,它的StartCopy方法只接受一个Uri(没有其他重载)。

您需要做的是获取CloudBlockBlob的引用,并且StartCopy方法也有其他重载。

var destinationBlob = container.GetBlockBlobReference(imageName);

enter image description here