public async Task <ActionResult> DownloadFileAsync(string id) { if (Guid.TryParse(id, out var guid)) { ServedFile servedFile = await _ServedFileService.GetAsync(guid); if (servedFile != ServedFile.Empty) { await _ServedFileService.IncrementDownloadCount(guid); _Logger.LogInformation($"Downloading file \"{id}\""); return(File(_FileStorageService.GetFileStream(servedFile.Path), "application/octet-stream", servedFile.Name)); } else { _Logger.LogWarning($"No file is available with Id \"{id}\""); return(NotFound()); } } else { _Logger.LogWarning("Provided id is not a GUID"); return(BadRequest()); } }
public async Task <IActionResult> UploadFileAsync([FromForm] IFormFile file) { if (file == null || file.Length == 0) { _Logger.LogWarning("Empty update file uploaded"); return(BadRequest()); } var filepath = await _FileStorageService.UploadFileAsync(file); ServedFile servedFile = await _ServedFileService.CreateAsync(new ServedFile(file.FileName, filepath, file.Length, DateTime.Now)); return(Ok(servedFile)); }
public async Task <ActionResult <ServedFile> > GetServedFileAsync(string id) { if (Guid.TryParse(id, out var guid)) { ServedFile servedFile = await _ServedFileService.GetAsync(guid); if (servedFile != ServedFile.Empty) { return(Ok(servedFile)); } else { _Logger.LogWarning($"No file is available with Id \"{id}\""); return(NotFound()); } } else { _Logger.LogWarning("Provided id is not a GUID"); return(BadRequest()); } }
public Task <ServedFile> CreateAsync(ServedFile servedFile) { _ServedFiles.Add(servedFile.Id, servedFile); return(Task.FromResult(servedFile)); }