The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UploadController.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Upload.ViewModels;
  7. using Teknik.Controllers;
  8. namespace Teknik.Areas.Upload.Controllers
  9. {
  10. public class UploadController : DefaultController
  11. {
  12. // GET: Upload/Upload
  13. [HttpGet]
  14. [AllowAnonymous]
  15. public ActionResult Index()
  16. {
  17. return View(new UploadViewModel());
  18. }
  19. // GET: Upload/Upload
  20. [HttpGet]
  21. [AllowAnonymous]
  22. public ActionResult Download(string url)
  23. {
  24. return View(new UploadViewModel());
  25. }
  26. [HttpPost]
  27. [AllowAnonymous]
  28. [ValidateAntiForgeryToken]
  29. public ActionResult Upload(string iv)
  30. {
  31. Models.Upload upload = null;
  32. foreach (string fileName in Request.Files)
  33. {
  34. HttpPostedFileBase file = Request.Files[fileName];
  35. //Save file content goes here
  36. string fName = file.FileName;
  37. if (file != null && file.ContentLength > 0)
  38. {
  39. upload = Uploader.SaveFile(file, iv);
  40. break;
  41. }
  42. }
  43. if (upload != null)
  44. {
  45. return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }) } }, "text/plain");
  46. }
  47. return Json(new { error = "Unable to upload file" });
  48. }
  49. [HttpPost]
  50. [AllowAnonymous]
  51. [ValidateAntiForgeryToken]
  52. public ActionResult Delete(string url, string deleteKey)
  53. {
  54. return Json(new { result = true });
  55. }
  56. [HttpPost]
  57. [AllowAnonymous]
  58. [ValidateAntiForgeryToken]
  59. public ActionResult GenerateDeleteKey(string uploadID)
  60. {
  61. return Json(new { result = "temp-delete-key" });
  62. }
  63. }
  64. }