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 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. using nClam;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using Teknik.Areas.Upload.ViewModels;
  7. using Teknik.Areas.Users.Utility;
  8. using Teknik.Controllers;
  9. using Teknik.Filters;
  10. using Teknik.Utilities;
  11. using Teknik.Models;
  12. using Teknik.Attributes;
  13. using System.Text;
  14. using Teknik.Utilities.Cryptography;
  15. using Teknik.Data;
  16. using Teknik.Configuration;
  17. using Microsoft.Extensions.Logging;
  18. using Microsoft.AspNetCore.Mvc;
  19. using Microsoft.AspNetCore.Authorization;
  20. using System.Threading.Tasks;
  21. using Microsoft.EntityFrameworkCore;
  22. using Microsoft.AspNetCore.Http;
  23. using Teknik.Logging;
  24. using Teknik.Areas.Users.Models;
  25. namespace Teknik.Areas.Upload.Controllers
  26. {
  27. [Authorize]
  28. [Area("Upload")]
  29. public class UploadController : DefaultController
  30. {
  31. public UploadController(ILogger<Logger> logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { }
  32. [HttpGet]
  33. [AllowAnonymous]
  34. [TrackPageView]
  35. public async Task<IActionResult> Index()
  36. {
  37. ViewBag.Title = "Upload Files";
  38. UploadViewModel model = new UploadViewModel();
  39. model.CurrentSub = Subdomain;
  40. model.Encrypt = false;
  41. model.ExpirationLength = 1;
  42. model.ExpirationUnit = ExpirationUnit.Days;
  43. model.MaxUploadSize = _config.UploadConfig.MaxUploadSize;
  44. if (User.Identity.IsAuthenticated)
  45. {
  46. User user = UserHelper.GetUser(_dbContext, User.Identity.Name);
  47. if (user != null)
  48. {
  49. model.Encrypt = user.UploadSettings.Encrypt;
  50. model.ExpirationLength = user.UploadSettings.ExpirationLength;
  51. model.ExpirationUnit = user.UploadSettings.ExpirationUnit;
  52. model.Vaults = user.Vaults.ToList();
  53. model.CurrentTotalSize = user.Uploads.Sum(u => u.ContentLength);
  54. model.MaxUploadSize = _config.UploadConfig.MaxUploadSizeBasic;
  55. model.MaxTotalSize = _config.UploadConfig.MaxTotalSizeBasic;
  56. IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, User.Identity.Name);
  57. if (userInfo.AccountType == AccountType.Premium)
  58. {
  59. model.MaxUploadSize = _config.UploadConfig.MaxUploadSizePremium;
  60. model.MaxTotalSize = _config.UploadConfig.MaxTotalSizePremium;
  61. }
  62. if (user.UploadSettings.MaxUploadStorage != null)
  63. model.MaxTotalSize = user.UploadSettings.MaxUploadStorage.Value;
  64. if (model.CurrentTotalSize >= model.MaxTotalSize)
  65. {
  66. model.Error = true;
  67. model.ErrorMessage = string.Format("Account storage limit exceeded: {0} / {1}", StringHelper.GetBytesReadable(model.CurrentTotalSize), StringHelper.GetBytesReadable(model.MaxTotalSize));
  68. }
  69. }
  70. }
  71. return View(model);
  72. }
  73. [HttpPost]
  74. [AllowAnonymous]
  75. [DisableRequestSizeLimit]
  76. public async Task<IActionResult> Upload([FromForm] UploadFileViewModel uploadFile)
  77. {
  78. try
  79. {
  80. if (_config.UploadConfig.UploadEnabled)
  81. {
  82. long maxUploadSize = _config.UploadConfig.MaxUploadSize;
  83. if (User.Identity.IsAuthenticated)
  84. {
  85. maxUploadSize = _config.UploadConfig.MaxUploadSizeBasic;
  86. long maxTotalSize = _config.UploadConfig.MaxTotalSizeBasic;
  87. IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, User.Identity.Name);
  88. if (userInfo.AccountType == AccountType.Premium)
  89. {
  90. maxUploadSize = _config.UploadConfig.MaxUploadSizePremium;
  91. maxTotalSize = _config.UploadConfig.MaxTotalSizePremium;
  92. }
  93. // Check account total limits
  94. var user = UserHelper.GetUser(_dbContext, User.Identity.Name);
  95. if (user.UploadSettings.MaxUploadStorage != null)
  96. maxTotalSize = user.UploadSettings.MaxUploadStorage.Value;
  97. var userUploadSize = user.Uploads.Sum(u => u.ContentLength);
  98. if (userUploadSize + uploadFile.file.Length > maxTotalSize)
  99. {
  100. return Json(new { error = new { message = string.Format("Account storage limit exceeded. {0} / {1}", StringHelper.GetBytesReadable(userUploadSize + uploadFile.file.Length), StringHelper.GetBytesReadable(maxTotalSize)) } });
  101. }
  102. }
  103. else
  104. {
  105. // Non-logged in users are defaulted to 1 day expiration
  106. uploadFile.options.ExpirationUnit = ExpirationUnit.Days;
  107. uploadFile.options.ExpirationLength = 1;
  108. }
  109. if (uploadFile.file.Length <= maxUploadSize)
  110. {
  111. // convert file to bytes
  112. long contentLength = uploadFile.file.Length;
  113. // Scan the file to detect a virus
  114. if (_config.UploadConfig.VirusScanEnable)
  115. {
  116. using (Stream fs = uploadFile.file.OpenReadStream())
  117. {
  118. ClamClient clam = new ClamClient(_config.UploadConfig.ClamServer, _config.UploadConfig.ClamPort);
  119. clam.MaxStreamSize = maxUploadSize;
  120. ClamScanResult scanResult = await clam.SendAndScanFileAsync(fs);
  121. switch (scanResult.Result)
  122. {
  123. case ClamScanResults.Clean:
  124. break;
  125. case ClamScanResults.VirusDetected:
  126. return Json(new { error = new { message = string.Format("Virus Detected: {0}. As per our <a href=\"{1}\">Terms of Service</a>, Viruses are not permited.", scanResult.InfectedFiles.First().VirusName, Url.SubRouteUrl("tos", "TOS.Index")) } });
  127. case ClamScanResults.Error:
  128. return Json(new { error = new { message = string.Format("Error scanning the file upload for viruses. {0}", scanResult.RawResult) } });
  129. case ClamScanResults.Unknown:
  130. return Json(new { error = new { message = string.Format("Unknown result while scanning the file upload for viruses. {0}", scanResult.RawResult) } });
  131. }
  132. }
  133. }
  134. // Check content type restrictions (Only for encrypting server side
  135. if (!uploadFile.options.Encrypt)
  136. {
  137. if (_config.UploadConfig.RestrictedContentTypes.Contains(uploadFile.fileType) || _config.UploadConfig.RestrictedExtensions.Contains(uploadFile.fileExt))
  138. {
  139. return Json(new { error = new { message = "File Type Not Allowed" } });
  140. }
  141. }
  142. using (Stream fs = uploadFile.file.OpenReadStream())
  143. {
  144. Models.Upload upload = UploadHelper.SaveFile(_dbContext,
  145. _config,
  146. fs,
  147. uploadFile.fileType,
  148. contentLength,
  149. !uploadFile.options.Encrypt,
  150. uploadFile.options.ExpirationUnit,
  151. uploadFile.options.ExpirationLength,
  152. uploadFile.fileExt,
  153. uploadFile.iv, null,
  154. uploadFile.keySize,
  155. uploadFile.blockSize);
  156. if (upload != null)
  157. {
  158. if (User.Identity.IsAuthenticated)
  159. {
  160. Users.Models.User user = UserHelper.GetUser(_dbContext, User.Identity.Name);
  161. if (user != null)
  162. {
  163. upload.UserId = user.UserId;
  164. _dbContext.Entry(upload).State = EntityState.Modified;
  165. _dbContext.SaveChanges();
  166. }
  167. }
  168. return Json(new { result = new
  169. {
  170. name = upload.Url,
  171. url = Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Url }),
  172. contentType = upload.ContentType,
  173. contentLength = StringHelper.GetBytesReadable(upload.ContentLength),
  174. contentLengthRaw = upload.ContentLength,
  175. deleteUrl = Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = upload.Url, key = upload.DeleteKey }),
  176. expirationUnit = uploadFile.options.ExpirationUnit.ToString(),
  177. expirationLength = uploadFile.options.ExpirationLength
  178. } });
  179. }
  180. }
  181. return Json(new { error = new { message = "Unable to upload file" } });
  182. }
  183. else
  184. {
  185. return Json(new { error = new { message = "File Too Large. Max file size is " + StringHelper.GetBytesReadable(maxUploadSize) } });
  186. }
  187. }
  188. return Json(new { error = new { message = "Uploads are disabled" } });
  189. }
  190. catch (Exception ex)
  191. {
  192. return Json(new { error = new { message = "Exception while uploading file: " + ex.GetFullMessage(true) } });
  193. }
  194. }
  195. [HttpGet]
  196. [AllowAnonymous]
  197. [TrackPageView]
  198. [ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)]
  199. public async Task<IActionResult> Download(string file)
  200. {
  201. if (_config.UploadConfig.DownloadEnabled)
  202. {
  203. ViewBag.Title = "Download " + file;
  204. string fileName = string.Empty;
  205. string url = string.Empty;
  206. string key = string.Empty;
  207. string iv = string.Empty;
  208. string contentType = string.Empty;
  209. long contentLength = 0;
  210. bool premiumAccount = false;
  211. DateTime dateUploaded = new DateTime();
  212. Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault();
  213. if (upload != null)
  214. {
  215. // Check Expiration
  216. if (UploadHelper.CheckExpiration(upload))
  217. {
  218. DeleteFile(upload);
  219. return new StatusCodeResult(StatusCodes.Status404NotFound);
  220. }
  221. upload.Downloads += 1;
  222. _dbContext.Entry(upload).State = EntityState.Modified;
  223. _dbContext.SaveChanges();
  224. fileName = upload.FileName;
  225. url = upload.Url;
  226. key = upload.Key;
  227. iv = upload.IV;
  228. contentType = upload.ContentType;
  229. contentLength = upload.ContentLength;
  230. dateUploaded = upload.DateUploaded;
  231. if (User.Identity.IsAuthenticated)
  232. {
  233. IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, User.Identity.Name);
  234. premiumAccount = userInfo.AccountType == AccountType.Premium;
  235. }
  236. if (!premiumAccount && upload.User != null)
  237. {
  238. IdentityUserInfo userInfo = await IdentityHelper.GetIdentityUserInfo(_config, upload.User.Username);
  239. premiumAccount = userInfo.AccountType == AccountType.Premium;
  240. }
  241. }
  242. else
  243. {
  244. return new StatusCodeResult(StatusCodes.Status404NotFound);
  245. }
  246. // We don't have the key, so we need to decrypt it client side
  247. if (string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(iv))
  248. {
  249. DownloadViewModel model = new DownloadViewModel();
  250. model.CurrentSub = Subdomain;
  251. model.FileName = file;
  252. model.ContentType = contentType;
  253. model.ContentLength = contentLength;
  254. model.IV = iv;
  255. model.Decrypt = true;
  256. return View(model);
  257. }
  258. else if (!premiumAccount && _config.UploadConfig.MaxDownloadSize < contentLength)
  259. {
  260. // We want to force them to the dl page due to them being over the max download size for embedded content
  261. DownloadViewModel model = new DownloadViewModel();
  262. model.CurrentSub = Subdomain;
  263. model.FileName = file;
  264. model.ContentType = contentType;
  265. model.ContentLength = contentLength;
  266. model.Decrypt = false;
  267. return View(model);
  268. }
  269. else // We have the key, so that means server side decryption
  270. {
  271. // Check for the cache
  272. bool isCached = false;
  273. string modifiedSince = Request.Headers["If-Modified-Since"];
  274. if (!string.IsNullOrEmpty(modifiedSince))
  275. {
  276. DateTime modTime = new DateTime();
  277. bool parsed = DateTime.TryParse(modifiedSince, out modTime);
  278. if (parsed)
  279. {
  280. if ((modTime - dateUploaded).TotalSeconds <= 1)
  281. {
  282. isCached = true;
  283. }
  284. }
  285. }
  286. if (isCached)
  287. {
  288. return new StatusCodeResult(StatusCodes.Status304NotModified);
  289. }
  290. else
  291. {
  292. string subDir = fileName[0].ToString();
  293. string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, fileName);
  294. long startByte = 0;
  295. long endByte = contentLength - 1;
  296. long length = contentLength;
  297. if (System.IO.File.Exists(filePath))
  298. {
  299. #region Range Calculation
  300. // Are they downloading it by range?
  301. bool byRange = !string.IsNullOrEmpty(Request.Headers["Range"]); // We do not support ranges
  302. // check to see if we need to pass a specified range
  303. if (byRange)
  304. {
  305. long anotherStart = startByte;
  306. long anotherEnd = endByte;
  307. string[] arr_split = Request.Headers["Range"].ToString().Split(new char[] { '=' });
  308. string range = arr_split[1];
  309. // Make sure the client hasn't sent us a multibyte range
  310. if (range.IndexOf(",") > -1)
  311. {
  312. // (?) Shoud this be issued here, or should the first
  313. // range be used? Or should the header be ignored and
  314. // we output the whole content?
  315. Response.Headers.Add("Content-Range", "bytes " + startByte + "-" + endByte + "/" + contentLength);
  316. return new StatusCodeResult(StatusCodes.Status416RequestedRangeNotSatisfiable);
  317. }
  318. // If the range starts with an '-' we start from the beginning
  319. // If not, we forward the file pointer
  320. // And make sure to get the end byte if spesified
  321. if (range.StartsWith("-"))
  322. {
  323. // The n-number of the last bytes is requested
  324. anotherStart = startByte - Convert.ToInt64(range.Substring(1));
  325. }
  326. else
  327. {
  328. arr_split = range.Split(new char[] { '-' });
  329. anotherStart = Convert.ToInt64(arr_split[0]);
  330. long temp = 0;
  331. anotherEnd = (arr_split.Length > 1 && Int64.TryParse(arr_split[1].ToString(), out temp)) ? Convert.ToInt64(arr_split[1]) : contentLength;
  332. }
  333. /* Check the range and make sure it's treated according to the specs.
  334. * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  335. */
  336. // End bytes can not be larger than $end.
  337. anotherEnd = (anotherEnd > endByte) ? endByte : anotherEnd;
  338. // Validate the requested range and return an error if it's not correct.
  339. if (anotherStart > anotherEnd || anotherStart > contentLength - 1 || anotherEnd >= contentLength)
  340. {
  341. Response.Headers.Add("Content-Range", "bytes " + startByte + "-" + endByte + "/" + contentLength);
  342. return new StatusCodeResult(StatusCodes.Status416RequestedRangeNotSatisfiable);
  343. }
  344. startByte = anotherStart;
  345. endByte = anotherEnd;
  346. length = endByte - startByte + 1; // Calculate new content length
  347. // Ranges are response of 206
  348. Response.StatusCode = 206;
  349. }
  350. #endregion
  351. // Set Last Modified
  352. Response.GetTypedHeaders().LastModified = dateUploaded;
  353. // We accept ranges
  354. Response.Headers.Add("Accept-Ranges", "0-" + contentLength);
  355. // Notify the client the byte range we'll be outputting
  356. Response.Headers.Add("Content-Range", "bytes " + startByte + "-" + endByte + "/" + contentLength);
  357. // Notify the client the content length we'll be outputting
  358. Response.Headers.Add("Content-Length", length.ToString());
  359. // Set the content type of this response
  360. Response.Headers.Add("Content-Type", contentType);
  361. // Create content disposition
  362. var cd = new System.Net.Mime.ContentDisposition
  363. {
  364. FileName = url,
  365. Inline = true
  366. };
  367. Response.Headers.Add("Content-Disposition", cd.ToString());
  368. // Read in the file
  369. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  370. // Reset file stream to starting position (or start of range)
  371. fs.Seek(startByte, SeekOrigin.Begin);
  372. try
  373. {
  374. // If the IV is set, and Key is set, then decrypt it while sending
  375. if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(iv))
  376. {
  377. byte[] keyBytes = Encoding.UTF8.GetBytes(key);
  378. byte[] ivBytes = Encoding.UTF8.GetBytes(iv);
  379. return new BufferedFileStreamResult(contentType, async (response) => await ResponseHelper.StreamToOutput(response, true, new AesCounterStream(fs, false, keyBytes, ivBytes), (int)length, _config.UploadConfig.ChunkSize), false);
  380. }
  381. else // Otherwise just send it
  382. {
  383. // Send the file
  384. return new BufferedFileStreamResult(contentType, async (response) => await ResponseHelper.StreamToOutput(response, true, fs, (int)length, _config.UploadConfig.ChunkSize), false);
  385. }
  386. }
  387. catch (Exception ex)
  388. {
  389. _logger.LogWarning(ex, "Error in Download: {url}", new { url });
  390. }
  391. }
  392. }
  393. return new StatusCodeResult(StatusCodes.Status404NotFound);
  394. }
  395. }
  396. return new StatusCodeResult(StatusCodes.Status403Forbidden);
  397. }
  398. [HttpPost]
  399. [AllowAnonymous]
  400. public IActionResult DownloadData(string file, bool decrypt)
  401. {
  402. if (_config.UploadConfig.DownloadEnabled)
  403. {
  404. Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault();
  405. if (upload != null)
  406. {
  407. // Check Expiration
  408. if (UploadHelper.CheckExpiration(upload))
  409. {
  410. DeleteFile(upload);
  411. return Json(new { error = new { message = "File Does Not Exist" } });
  412. }
  413. string subDir = upload.FileName[0].ToString();
  414. string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
  415. if (System.IO.File.Exists(filePath))
  416. {
  417. // Notify the client the content length we'll be outputting
  418. Response.Headers.Add("Content-Length", upload.ContentLength.ToString());
  419. // Create content disposition
  420. var cd = new System.Net.Mime.ContentDisposition
  421. {
  422. FileName = upload.Url,
  423. Inline = true
  424. };
  425. // Set the content type of this response
  426. Response.Headers.Add("Content-Type", upload.ContentType);
  427. Response.Headers.Add("Content-Disposition", cd.ToString());
  428. // Read in the file
  429. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  430. // If the IV is set, and Key is set, then decrypt it while sending
  431. if (decrypt && !string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
  432. {
  433. byte[] keyBytes = Encoding.UTF8.GetBytes(upload.Key);
  434. byte[] ivBytes = Encoding.UTF8.GetBytes(upload.IV);
  435. return new BufferedFileStreamResult(upload.ContentType, (response) => ResponseHelper.StreamToOutput(response, true, new AesCounterStream(fs, false, keyBytes, ivBytes), (int)upload.ContentLength, _config.UploadConfig.ChunkSize), false);
  436. }
  437. else // Otherwise just send it
  438. {
  439. // Send the file
  440. return new BufferedFileStreamResult(upload.ContentType, (response) => ResponseHelper.StreamToOutput(response, true, fs, (int)upload.ContentLength, _config.UploadConfig.ChunkSize), false);
  441. }
  442. }
  443. }
  444. return Json(new { error = new { message = "File Does Not Exist" } });
  445. }
  446. return Json(new { error = new { message = "Downloads are disabled" } });
  447. }
  448. [HttpGet]
  449. [AllowAnonymous]
  450. public IActionResult DeleteByKey(string file, string key)
  451. {
  452. ViewBag.Title = "File Delete | " + file ;
  453. Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault();
  454. if (upload != null)
  455. {
  456. DeleteViewModel model = new DeleteViewModel();
  457. model.File = file;
  458. if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
  459. {
  460. DeleteFile(upload);
  461. model.Deleted = true;
  462. }
  463. else
  464. {
  465. model.Deleted = false;
  466. }
  467. return View(model);
  468. }
  469. return new StatusCodeResult(StatusCodes.Status404NotFound);
  470. }
  471. [HttpPost]
  472. public IActionResult GenerateDeleteKey(string file)
  473. {
  474. Models.Upload upload = _dbContext.Uploads.Where(up => up.Url == file).FirstOrDefault();
  475. if (upload != null)
  476. {
  477. if (upload.User.Username == User.Identity.Name)
  478. {
  479. string delKey = StringHelper.RandomString(_config.UploadConfig.DeleteKeyLength);
  480. upload.DeleteKey = delKey;
  481. _dbContext.Entry(upload).State = EntityState.Modified;
  482. _dbContext.SaveChanges();
  483. return Json(new { result = new { url = Url.SubRouteUrl("u", "Upload.DeleteByKey", new { file = file, key = delKey }) } });
  484. }
  485. return Json(new { error = new { message = "You do not own this upload" } });
  486. }
  487. return Json(new { error = new { message = "Invalid URL" } });
  488. }
  489. [HttpPost]
  490. [HttpOptions]
  491. public IActionResult Delete(string id)
  492. {
  493. Models.Upload foundUpload = _dbContext.Uploads.Where(u => u.Url == id).FirstOrDefault();
  494. if (foundUpload != null)
  495. {
  496. if (foundUpload.User.Username == User.Identity.Name)
  497. {
  498. DeleteFile(foundUpload);
  499. return Json(new { result = true });
  500. }
  501. return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
  502. }
  503. return Json(new { error = new { message = "This Upload does not exist" } });
  504. }
  505. private void DeleteFile(Models.Upload upload)
  506. {
  507. string subDir = upload.FileName[0].ToString();
  508. string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
  509. // Delete the File
  510. if (System.IO.File.Exists(filePath))
  511. {
  512. System.IO.File.Delete(filePath);
  513. }
  514. // Delete from the DB
  515. _dbContext.Uploads.Remove(upload);
  516. _dbContext.SaveChanges();
  517. }
  518. }
  519. }