MountainBiker
MountainBiker

Reputation: 411

Azure Storage API "StartCopyFromBlob"

I am trying to copy a blob from one location to another and it seems like this method is obsolete. Everything I've read says I should use "StartCopy". However, when I try this it doesn't copy the blob. I just get a 404 error at the destination.

I don't seem to be able to find any documentation for this. Can anyone advise me on how to do this in the latest version of the API or point me in the direction of some docs.

Uri uploadUri = new Uri(destinationLocator.Path);
string assetContainerName = uploadUri.Segments[1];
CloudBlobContainer assetContainer =
    cloudBlobClient.GetContainerReference(assetContainerName);
string fileName = HttpUtility.UrlDecode(Path.GetFileName(model.BlockBlob.Uri.AbsoluteUri));

var sourceCloudBlob = mediaBlobContainer.GetBlockBlobReference(fileName);
sourceCloudBlob.FetchAttributes();

if (sourceCloudBlob.Properties.Length > 0)
{
    IAssetFile assetFile = asset.AssetFiles.Create(fileName);
    var destinationBlob = assetContainer.GetBlockBlobReference(fileName);

    destinationBlob.DeleteIfExists();
    destinationBlob.StartCopyFromBlob(sourceCloudBlob);
    destinationBlob.FetchAttributes();
    if (sourceCloudBlob.Properties.Length != destinationBlob.Properties.Length)
        model.UploadStatusMessage += "Failed to copy as Media Asset!";
}

Upvotes: 2

Views: 936

Answers (1)

MountainBiker
MountainBiker

Reputation: 411

I'm just posting my comment as the answer to make it easier to see.

It wasn't the access level of the container. It wasn't anything to do with StartCopy either. It turned out to be these lines of code.

var mediaBlobContainer = cloudBlobClient.GetContainerReference(cloudBlobClient.BaseUri + "temporarymedia");
mediaBlobContainer.CreateIfNotExists(); 

Apparently I shouldn't be supplying the cloudBlobClient.BaseUri, just the name temporarymedia.

var mediaBlobContainer = cloudBlobClient.GetContainerReference("temporarymedia"); 

There was no relevant error message though. Hopefully it'll save another Azure newbie some time in future.

Upvotes: 1

Related Questions