public async Task <IActionResult> UploadFileAsync(string fileHash) { try { if (string.IsNullOrWhiteSpace(fileHash)) { return(BadRequest()); } var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true); using var readStream = Request.Body; if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } using var writeStream = System.IO.File.OpenWrite(fullPath); await readStream.CopyToAsync(writeStream); return(Ok()); } catch { return(BadRequest()); } }
public IActionResult DeleteFile(string fileHash) { try { if (string.IsNullOrWhiteSpace(fileHash)) { return(BadRequest()); } var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true); if (fullPath == null) { return(BadRequest()); } System.IO.File.Delete(fullPath); return(Ok()); } catch { return(BadRequest()); } }
public IActionResult DownloadFileAsync(string fileHash) { try { if (string.IsNullOrWhiteSpace(fileHash)) { return(BadRequest()); } var fullPath = VolumeHelper.GetFullPathFromHash(fileHash, true); if (fullPath == null) { return(BadRequest()); } return(File(fullPath, GetContentType(fullPath))); } catch { return(BadRequest()); } }