1
votes

Trying to move a append blob to another container after processing it. I am first just trying to copy it, then I will delete it (unless there is a actual move function?)

Using C#

I keep getting a 404 : The remote server returned an error: (404) Not Found. ---> System.Net.WebException : The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse()

I have tried creating a SasToken at both the container and blob level.

private static void  copyBlob(messageClass msgPassed, CloudStorageAccount storageAccount)
    {
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer sourceContainer = blobClient.GetContainerReference(receiveScanContainer);

        //create a SAS on source blob container with "read" permission. We will append this SAS later
        var sasToken = sourceContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
        {
            Permissions = SharedAccessBlobPermissions.Read,
            SharedAccessExpiryTime = DateTime.UtcNow.AddDays(1),
        });

        CloudBlobContainer targetContainer = blobClient.GetContainerReference(archiveContainer);

        CloudAppendBlob sourceBlob = sourceContainer.GetAppendBlobReference(msgPassed.currentName);
        var sasToken2 = sourceBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
        {
            Permissions = SharedAccessBlobPermissions.Read,
            SharedAccessExpiryTime = DateTime.UtcNow.AddDays(1),

        });

       CloudAppendBlob targetBlob = targetContainer.GetAppendBlobReference(msgPassed.currentName);
        string name = sourceBlob.Uri.Segments.Last();
       CloudAppendBlob destBlob = targetContainer.GetAppendBlobReference(name+sasToken2);

        targetBlob.StartCopy(destBlob);
    }
1

1 Answers

0
votes

OK...dug into it more. The below works. I also was passing the name of the target container slightly wrong (one letter off) from what the container name actually was.

    private static void  copyBlob(messageClass msgPassed, CloudStorageAccount storageAccount)
    {


        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer sourceContainer = blobClient.GetContainerReference(receiveScanContainer);

        CloudBlobContainer targetContainer = blobClient.GetContainerReference(archiveContainer);

        CloudAppendBlob sourceBlob = sourceContainer.GetAppendBlobReference(msgPassed.currentName);
        CloudAppendBlob targetBlob = targetContainer.GetAppendBlobReference(msgPassed.currentName);


        targetBlob.StartCopy(sourceBlob);
    }