Add project files.
This commit is contained in:
		
							
								
								
									
										61
									
								
								Core.Blueprint.DAL.API/Controllers/BlobStorageController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								Core.Blueprint.DAL.API/Controllers/BlobStorageController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| 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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin