Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> FileUploadForm(FileUploadForm 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, "intex-fagelgamous", "AKIAVY5M47Y5S26WCNPL");
                }
                else


                {
                    ModelState.AddModelError("File", "The file is too large.");
                }
            }

            return(View());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(ImageUploadViewModel viewModel)
        {
            string objectKey = $"Burials/{viewModel.fileForm.FileName}-{DateTime.Now.ToString()}";


            Image img = new Image
            {
                BurialId         = Convert.ToDecimal(viewModel.BurialId),
                ImagePodecimaler = S3Upload.GeneratePreSignedURL(objectKey),
                Burial           = _context.Burials.Where(x => x.BurialId == Convert.ToDecimal(viewModel.BurialId)).FirstOrDefault()
            };

            if (ModelState.IsValid)
            {
                _context.Add(img);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            ViewData["BurialId"] = new SelectList(_context.Burials, "BurialId", "BurialId", img.BurialId);

            using (var memoryStream = new MemoryStream())
            {
                await viewModel.fileForm.CopyToAsync(memoryStream);

                // Upload the file if less than 10 MB
                if (memoryStream.Length < 10485760)
                {
                    await S3Upload.UploadFileAsync(memoryStream, "arn:aws:s3:us-east-1:524546685232:accesspoint/is410", objectKey);
                }
                else
                {
                    ModelState.AddModelError("File", "The file is too large.");
                }
            }

            return(RedirectToAction("Details", "Burial", new { ID = viewModel.BurialId }));
        }