adding
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
using Azure.Storage.Blobs;
|
||||
using Azure.Storage.Blobs.Models;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess;
|
||||
|
||||
public class BlobApiDao : IBlobApiDao
|
||||
{
|
||||
private readonly BlobContainerClient _client;
|
||||
|
||||
public BlobApiDao(IBlobStorageClient storageClient)
|
||||
{
|
||||
_client = storageClient.GetClient();
|
||||
}
|
||||
|
||||
public async Task<Guid> SaveDocumentToBlob(byte[] fileData)
|
||||
{
|
||||
var blobDocumentId = Guid.NewGuid();
|
||||
|
||||
using var stream = new MemoryStream(fileData, false);
|
||||
await _client.GetBlobClient(blobDocumentId.ToString()).UploadAsync(stream);
|
||||
return blobDocumentId;
|
||||
}
|
||||
|
||||
public async Task UpdateDocumentInBlob(Guid blobDocumentId, byte[] fileData)
|
||||
{
|
||||
using var stream = new MemoryStream(fileData, false);
|
||||
await _client.GetBlobClient(blobDocumentId.ToString()).UploadAsync(stream, true);
|
||||
}
|
||||
|
||||
public async Task<Response> RemoveDocumentFromBlob(Guid blobDocumentId)
|
||||
{
|
||||
return await _client.GetBlobClient(blobDocumentId.ToString())
|
||||
.DeleteAsync(DeleteSnapshotsOption.IncludeSnapshots);
|
||||
}
|
||||
|
||||
public async Task<Response<BlobDownloadStreamingResult>> GetDocumentFromBlob(Guid blobDocumentId)
|
||||
{
|
||||
return await _client.GetBlobClient(blobDocumentId.ToString()).DownloadStreamingAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user