smatsson / TusAzureStore

POC of a store for tusdotnet using Azure Storage
MIT License
4 stars 1 forks source link

Is there an Azure.Storage.Blobs implementation anywhere? #1

Open thutson opened 3 years ago

thutson commented 3 years ago

The code in these repo errors out and WindowsAzure.Storage has been deprecated. I'm looking for a more recent repo using the newer Azure.Storage.Blobs libs? I don't have too much time to spend on this since I'm just tinkering but here's my ten minute implementation that doesn't work:

`public class TusAzureBlobStore : ITusStore { private readonly Lazy _client;

    public TusAzureBlobStore(string connectionString, string containerName)
    {
        _client = new Lazy<BlobContainerClient>(() => BlobContainerHelper.GetBlobContainerClient(connectionString, containerName));
    }

    public async Task<long> AppendDataAsync(string fileId, Stream stream, CancellationToken cancellationToken)
    {
        var file = GetContainer().GetBlobClient(fileId);
        await file.UploadAsync(stream, cancellationToken);

        return stream.Length;
    }

    public async Task<bool> FileExistAsync(string fileId, CancellationToken cancellationToken)
    {
        return await GetContainer().GetBlobClient(fileId).ExistsAsync(cancellationToken);
    }

    public async Task<long?> GetUploadLengthAsync(string fileId, CancellationToken cancellationToken)
    {
        var file = GetContainer().GetBlobClient(fileId);
        var props = await file.GetPropertiesAsync();

        return props.Value.ContentLength;
    }

    public async Task<long> GetUploadOffsetAsync(string fileId, CancellationToken cancellationToken)
    {
        var file = GetContainer().GetBlobClient(fileId);
        var props = await file.GetPropertiesAsync();

        return props.Value.ContentLength;
    }
    private BlobContainerClient GetContainer()
    {
        return _client.Value;
    }
}
public class BlobContainerHelper {
    public static BlobContainerClient GetBlobContainerClient(string connectionString, string containerName) {
        return new BlobContainerClient(connectionString, containerName);
    }
}`
smatsson commented 3 years ago

Hi,

As you can see from the commit history - this is an old POC that I wrote 4 years ago to test that the architecture of tusdotnet works as intended. I have no idea if there are any other implementations using blob storage, sorry.