61 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Asp.Versioning;
 | |
| using Core.Blueprint.DAL.Storage.Contracts;
 | |
| using Core.Blueprint.Storage;
 | |
| using Microsoft.AspNetCore.Authorization;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| 
 | |
| namespace Core.Blueprint.DAL.API.Controllers
 | |
| {
 | |
|     [ApiVersion("1.0")]
 | |
|     [Route("api/v{api-version:apiVersion}/[controller]")]
 | |
|     [Produces("application/json")]
 | |
|     [ApiController]
 | |
|     [AllowAnonymous]
 | |
|     public class BlobStorageController(IBlobStorageService storageService) : ControllerBase
 | |
|     {
 | |
|         [HttpPost("UploadBlobFromFileBrowser")]
 | |
|         [Consumes("multipart/form-data")]
 | |
|         public async Task<IActionResult> UploadBlobAsync([FromQuery] string blobName, IFormFile file)
 | |
|         {
 | |
|             if (file == null || file.Length == 0)
 | |
|                 return BadRequest("No file uploaded.");
 | |
| 
 | |
|             using var stream = file.OpenReadStream();
 | |
| 
 | |
|             var result = await storageService.UploadBlobAsync(blobName, stream);
 | |
| 
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpPost("UploadBlob")]
 | |
|         public async Task<IActionResult> UploadBlobAsync([FromBody] BlobAddDto newBlob)
 | |
|         {
 | |
|             var result = await storageService.UploadBlobAsync(newBlob);
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpGet("GetBlobList")]
 | |
|         public async Task<IActionResult> GetBlobsListAsync([FromQuery] string? prefix)
 | |
|         {
 | |
|             var result = await storageService.GetBlobsListAsync(prefix).ConfigureAwait(false);
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpGet("DownloadBlob")]
 | |
|         public IActionResult DownloadBlobAsync([FromQuery] string blobName)
 | |
|         {
 | |
|             var result = storageService.DownloadBlobAsync(blobName);
 | |
| 
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpDelete("DeleteBlob")]
 | |
|         public async Task<IActionResult> DeleteFileAsync([FromQuery] string blobName)
 | |
|         {
 | |
|             var result = await storageService.DeleteBlobAsync(blobName).ConfigureAwait(false);
 | |
| 
 | |
|             if (result is null) return NotFound($"Blob {blobName} doesn't exist");
 | |
|             return Ok(result);
 | |
|         }
 | |
|     }
 | |
| } |