44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
|
|
|||
|
using Azure.Storage.Blobs;
|
|||
|
using Azure.Storage.Blobs.Models;
|
|||
|
using Azure.Storage.Blobs.Specialized;
|
|||
|
using DamageAssesment.Api.Documents.Interfaces;
|
|||
|
|
|||
|
namespace DamageAssesment.Api.Documents.Providers
|
|||
|
{
|
|||
|
public class AzureBlobService: IAzureBlobService
|
|||
|
{
|
|||
|
BlobServiceClient _blobClient;
|
|||
|
BlobContainerClient _containerClient;
|
|||
|
string azureConnectionString = "<Primary Connection String>";
|
|||
|
public AzureBlobService()
|
|||
|
{
|
|||
|
_blobClient = new BlobServiceClient(azureConnectionString);
|
|||
|
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
|
|||
|
}
|
|||
|
|
|||
|
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
|
|||
|
{
|
|||
|
|
|||
|
var azureResponse = new List<Azure.Response<BlobContentInfo>>();
|
|||
|
foreach (var file in files)
|
|||
|
{
|
|||
|
string fileName = file.FileName;
|
|||
|
using (var memoryStream = new MemoryStream())
|
|||
|
{
|
|||
|
file.CopyTo(memoryStream);
|
|||
|
memoryStream.Position = 0;
|
|||
|
var client = await _containerClient.UploadBlobAsync(fileName, memoryStream, default);
|
|||
|
azureResponse.Add(client);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
return azureResponse;
|
|||
|
}
|
|||
|
public void DeleteFile(string url)
|
|||
|
{
|
|||
|
var blob = _containerClient.GetBlockBlobClient(url);
|
|||
|
blob.DeleteIfExists();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|