Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Azure Storage Blob Upload TransactionScope

Is there somewhere a class to allow roll back with transactionscope on azure blockblob actions ?

I would like make this works:

  CloudBlockBlob blockBlob;

    private void UploadPicture(Stream iStream)
    {
        using(var ts = new TransactionScope())
        {
            blockBlob.UploadFromStream(iStream);

            throw new Exception();
            ts.Complete();
        }
    }

When the exception is raise, the uploaded file is not cancelled. If is not possible with transaction scope, how should I proceed ?

like image 282
Julian50 Avatar asked Nov 09 '22 16:11

Julian50


1 Answers

Azure Storage Client Library does not provide this support. If, however, cancellation support is acceptable for your scenario, you can use the UploadFromStreamAsync API with a CancellationToken. While it is asynchronously uploading the blob, you can cancel the operation. Depending on the operation's current progress, it will try to abort the upload.

like image 196
Serdar Ozler Avatar answered Nov 15 '22 07:11

Serdar Ozler