public async Task <IActionResult> FileUploadForm(FileUploadFormModal FileUpload) { using (var memoryStream = new MemoryStream()) { await FileUpload.FormFile.CopyToAsync(memoryStream); // Upload the file if less than 2 MB if (memoryStream.Length < 2097152) { string fileExtension = FileUpload.FormFile.FileName.Split(".")[1]; string randomId = Guid.NewGuid().ToString(); string fileName = randomId + "." + fileExtension; await S3Upload.UploadFileAsync(memoryStream, "egyptexcavation", "photos/" + fileName); string uploadUrl = "https://egyptexcavation.s3.amazonaws.com/photos/" + fileName; //_recordService.SavePhotoUrl(FileUpload.BurialID, uploadUrl); } else { ModelState.AddModelError("File", "The file is too large."); return(View(FileUpload)); } } return(View()); }
//Using FileUploadFormModal, store file selected by user //and generate attachment url. Upload to S3 and save necessary //information to Attachment table public async Task <IActionResult> FileUploadForm(FileUploadFormModal FileUpload, string attachmentCategory, string attachmentDescription, int byufegId) { //Copy file into memory stream to obtain length using (var memoryStream = new MemoryStream()) { await FileUpload.FormFile.CopyToAsync(memoryStream); // Upload the file if less than 15 MB if (memoryStream.Length < 15097152) { //Call UploadImage method from S3File class to upload to S3 await S3File.UploadImage(FileUpload.FormFile); //Load pertinent data to Attachment table var name = FileUpload.FormFile.FileName.Replace(" ", ""); context.Attachment.Add(new Attachment() { ByufegId = byufegId, Description = attachmentDescription, Category = attachmentCategory, AttachmentUrl = $"https://elasticbeanstalk-us-east-1-453718841465.s3.amazonaws.com/{name}" }); context.SaveChanges(); } else { ModelState.AddModelError("File", "The file is too large."); } } return(RedirectToAction("Data")); }
public async Task <IActionResult> FileUploadForm(FileUploadFormModal FileUpload) { using (var memoryStream = new MemoryStream()) { await FileUpload.FormFile.CopyToAsync(memoryStream); // Upload the file if less than 2 MB if (memoryStream.Length < 2097152) { await s3Upload.UploadFileAsync(memoryStream, "arn:aws:s3:us-east-1:963873112149:accesspoint/intex2-8accesspoint", "ASIA6A22QQBKVEFKUOPJ"); } else { ModelState.AddModelError("File", "The file is too large."); } } return(View()); }