Skip to content

Instantly share code, notes, and snippets.

@sefatanam
Created September 10, 2021 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sefatanam/bf48a9fdfa7fa1c344d1a5fdb3ec0726 to your computer and use it in GitHub Desktop.
Save sefatanam/bf48a9fdfa7fa1c344d1a5fdb3ec0726 to your computer and use it in GitHub Desktop.
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