Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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