William Borgo
William Borgo

Reputation: 444

Error "The specified resource does not exist" when trying to copy blob from storage to another

I'm trying to move a blob file from a container to another that is in another storage.

public void MoveFile(StorageConfig sourceConfig, StorageConfig destinationConfig, string sourceFilename, string destinationFilename)
    {
        var sContainer = GetBlobContainerReference(sourceConfig.ConnectionString, sourceConfig.ContainerName);
        var dContainer = GetBlobContainerReference(destinationConfig.ConnectionString, destinationConfig.ContainerName);

        var sBlob = sContainer.GetBlockBlobReference(sourceFilename);
        var dBlob = dContainer.GetBlockBlobReference(destinationFilename);

        dBlob.StartCopy(sBlob);

        sBlob.Delete(DeleteSnapshotsOption.IncludeSnapshots);
    }

I have distinct credentials for Source and Destination containers.

When I run this code, the error occurs on the line dBlob.StartCopy(sBlob);

And the error "The specified resource does not exist" is thrown.

The sBlob.Delete() works with no error, so it is reaching the source blob file.

I watch these variables:

sBlob.Exists() -> true
dBlob.Exists() -> false
sContainer.Exists() -> true
dContainer.Exists() -> true

So it can connect in both containers.

Did I need to create the destination blob first? I think not based on some codes I found in the internet.

Upvotes: 3

Views: 8193

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136136

For copying blob from one account to another, the source blob must be publicly accessible. This restriction does not apply when a blob is copied within same storage account.

The reason you are getting this error is most likely because your source blob is in a private container.

To fix this issue, create a SAS URL for the source blob with at least read permission and use that URL for copying blob.

Upvotes: 3

Related Questions