public async Task <IActionResult> SaveFile(IFormFile file, string fileId, int noteId) { //Set The connection string CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("storageConnectionString")); //Create a blob client CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); //Get a reference to a container CloudBlobContainer container = blobClient.GetContainerReference("files"); //Get a reference to a blob CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName); //Create or overwrite the blob with the contents of a local files using (var fileStream = file.OpenReadStream()) { await blockBlob.UploadFromStreamAsync(fileStream); } //Sending file to JS var newFileAttachment = new FileAttachment(); newFileAttachment.Name = file.FileName; newFileAttachment.Size = blockBlob.Properties.Length; newFileAttachment.URI = blockBlob.Uri.ToString(); var noteToAttachTo = _context.WebNotes.FirstOrDefault(x => x.Id == noteId); var user = await _userManager.GetUserAsync(HttpContext.User); _webNoteService.AddFileToNote(newFileAttachment, noteToAttachTo, user); return(RedirectToAction("Index")); }
public async Task <IActionResult> UploadFileAttachment(WebNote noteToAttachTo, string file) { var note = noteToAttachTo; var fileSplit = file.Split(","[0]); var fileTypeHeaders = fileSplit[0]; var convertedFile = Convert.FromBase64String(fileSplit[1]); var user = await _userManager.GetUserAsync(HttpContext.User); _webNoteService.AddFileToNote(noteToAttachTo, convertedFile, fileTypeHeaders, user); return(Ok()); }