public IActionResult Post() { string fileName = Request.Headers["FileName"]; Guid g = Guid.NewGuid(); var fileCrypto = new ChaChaFileCrypto(); var cs = fileCrypto.BcEncryptStream(Request.Body); _googleDriveInterface.UploadFile(g.ToString(), cs); var fileInfo = new DbFileInfo { FileId = g, FileName = fileName, Key = fileCrypto.Key, Iv = fileCrypto.Iv }; _databaseInterface.StoreFileDetails(fileInfo); Dictionary <string, string> responseDict = new Dictionary <string, string> { ["fileId"] = g.ToString() }; Response.Headers.Add("Access-Control-Allow-Origin", "*"); return(Ok(responseDict)); }
public IActionResult Get(string fileId) { Guid fileGuid; try { fileGuid = new Guid(fileId); } catch (FormatException) { return(NotFound()); } DbFileInfo fileInfo = _databaseInterface.GetFileInfo(fileGuid); if (fileInfo == null) { return(NotFound()); } var fileCrypto = new ChaChaFileCrypto() { Key = fileInfo.Key, Iv = fileInfo.Iv }; var dloadStream = new ProducerConsumerStream(1048576); _googleDriveInterface.DownloadFileAsync(fileId, dloadStream); var outStream = fileCrypto.BcDecryptStream(dloadStream); return(new FileCallbackResult(new MediaTypeHeaderValue("application/octet-stream"), async(outputStream, _) => { await outStream.CopyToAsync(outputStream); await outputStream.FlushAsync(); }) { FileDownloadName = fileInfo.FileName }); }