Calling UploadFromStream overwrites files by default - how can I make sure I only upload a blob if it isn't already in the container?
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); blockBlob.UploadFromStream(stream)
An append blob is composed of blocks and is optimized for append operations. When you modify an append blob, blocks are added to the end of the blob only, via the Append Block operation. Updating or deleting of existing blocks is not supported. Unlike a block blob, an append blob does not expose its block IDs.
Copy all containers, directories, and blobs to another storage account by using the azcopy copy command. This example encloses path arguments with single quotes (''). Use single quotes in all command shells except for the Windows Command Shell (cmd.exe).
Add an access condition to the code so that it checks against the ETag property of the blob - wildcards are allowed, so we want to only allow the upload if no blobs with this name have any etag (which is a roundabout way of saying, does this blob name exist).
You get a StorageException as detailed below.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); try { blockBlob.UploadFromStream(stream, accessCondition: AccessCondition.GenerateIfNoneMatchCondition("*")); } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.Conflict) { // Handle duplicate blob condition } throw; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With