Created
September 10, 2021 05:17
-
-
Save sefatanam/bf48a9fdfa7fa1c344d1a5fdb3ec0726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System; | |
using System.Threading.Tasks; | |
using azblob.Services; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
namespace azblob.Controllers | |
{ | |
public class BlobFilesController : Controller | |
{ | |
private readonly IBlobService _service; | |
public BlobFilesController(IBlobService blobService) | |
{ | |
_service = blobService; | |
} | |
[HttpGet] | |
public async Task<IActionResult> Index() | |
{ | |
var files = await _service.AllBlobs("azdemo"); | |
return View(files); | |
} | |
[HttpGet] | |
public IActionResult AddFile() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public async Task<IActionResult> AddFile(IFormFile file) | |
{ | |
if (file == null || file.Length < 1) return View(); | |
var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); | |
var res = await _service.UploadBlob(fileName, file, "azdemo"); | |
if (res) return RedirectToAction("Index"); | |
return View(); | |
} | |
[HttpGet] | |
public async Task<IActionResult> ViewFile(string name) | |
{ | |
var res = await _service.GetBlob(name, "azdemo"); | |
return Redirect(res); | |
} | |
[HttpGet] | |
public async Task<IActionResult> DeleteFile(string name) | |
{ | |
var res = await _service.DeleteBlob(name, "azdemo"); | |
return RedirectToAction("Index"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment