C# Azure Storage Blob Upload TransactionScope

不问归期 提交于 2020-01-14 09:35:47

问题


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:


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.



来源:https://stackoverflow.com/questions/29394413/c-sharp-azure-storage-blob-upload-transactionscope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!