5
votes

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 ?

1
what are you trying to achieve here? Is the objective to make the upload atomic so either the whole upload succeeds or nothing does? How large is your blob? - Atul Sikaria
@AtulSikaria-MSFT Yes I'm trying to make atomic upload with his metadata in my database. If something goes wrong I can rollback. The max size of the blob is 5 Mo. - Julian50
In that case you should not need a Transaction rolled around your update. Updates to blobs are atomic. Even if the blobs are uploaded in chunks, it is the final PutBlockList request that commits the blob, which should be atomic. - Atul Sikaria
@AtulSikaria-MSFT I think that We don't understand each other. I wanna make the "blob upload + sql transaction" atomic. Not the blob upload alone. - Julian50
@AtulSikaria-MSFT I have to go deeper but I think that azure.microsoft.com/fr-fr/services/documentdb should answer to my question - Julian50

1 Answers

1
votes

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.