public async Task <IActionResult> OnPostAsync(IFormFile file) { var fileName = Path.GetFileName(file.FileName); await _storageService.AddImageAsync(file.OpenReadStream(), fileName); return(RedirectToPage("Index", new { value = UploadSuccessParameter })); }
public async Task <IActionResult> OnPostAsync(IFormFile file) { var fileName = Path.GetFileName(file.FileName); DateTime now = DateTime.Now; var base64Time = Base64Encoder.GetBase64String($"{now.ToShortDateString()} {now.ToShortTimeString()}"); var base64File = Base64Encoder.GetBase64String(fileName); var user = User.Identities.FirstOrDefault(); await _storageService.AddImageAsync(file.OpenReadStream(), fileName, user.Name); return(RedirectToPage("UploadSuccess", new { file = base64File, time = base64Time })); }
public async Task <ActionResult> Upload(HttpPostedFileBase file) { if (file == null) { return(RedirectToAction("Index", new { value = "uploadFailure" })); } try { var image = await _storageService.AddImageAsync(file.InputStream, file.FileName); } catch (Exception e) { return(RedirectToAction("Index", new { value = "uploadFailure" })); } return(RedirectToAction("Index", new { value = "uploadSuccess" })); }
public async Task <IHttpActionResult> Upload() { _loggerService.LogInformation("start - upload faces"); if (!System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { _loggerService.LogError("Error- upload faces"); return(BadRequest("error upload")); } var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadedImage"]; if (httpPostedFile == null) { _loggerService.LogError("Error- upload faces"); return(BadRequest("error upload")); } var fileExtension = System.IO.Path.GetExtension(httpPostedFile.FileName); _loggerService.LogInformation( $"upload faces, fileName : {httpPostedFile.FileName}, extension : {fileExtension}"); var imagePath = await _storageService.AddImageAsync(httpPostedFile.InputStream, fileExtension); ImageFace imageFace = new ImageFace { ImagePath = imagePath, FaceAttributes = await _cognitiveService.DetectImageFaceAttributes(imagePath.ToString()) }; _loggerService.LogInformation($"end - faces attributes : { JsonConvert.SerializeObject(imageFace.FaceAttributes)}"); imageFace = await _imageFaceRepository.AddOrUpdateAsync(imageFace); _loggerService.LogInformation("end - upload faces"); return(Ok(new FaceModel(imageFace.Id, imageFace.ImagePath.ToString(), _mapper.Map <List <FaceAttributeModel> >(imageFace.FaceAttributes)))); }
public async Task <IHttpActionResult> Upload() { _loggerService.LogInformation("start - upload image"); if (!System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { _loggerService.LogError("Error- upload image"); return(BadRequest("error upload")); } var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadedImage"]; if (httpPostedFile == null) { _loggerService.LogError("Error- upload image"); return(BadRequest("error upload")); } var fileExtension = System.IO.Path.GetExtension(httpPostedFile.FileName); _loggerService.LogInformation( $"upload image, fileName : {httpPostedFile.FileName}, extension : {fileExtension}"); var imagePath = await _storageService.AddImageAsync(httpPostedFile.InputStream, fileExtension); ImageRecognition imageRecognition = new ImageRecognition { ImagePath = imagePath, AnalysisResult = await _cognitiveService.AnalyzeImage(imagePath.ToString()) }; _loggerService.LogInformation($"end - image attributes : { JsonConvert.SerializeObject(imageRecognition.AnalysisResult)}"); imageRecognition = await _imageRecognitionRepository.AddOrUpdateAsync(imageRecognition); _loggerService.LogInformation("end - upload image"); return(Ok(_mapper.Map <ImageRecognitionModel>(imageRecognition))); }
public async Task <ActionResult> Upload(HttpPostedFileBase file) { if (file == null) { return(RedirectToAction("Index", new { value = "uploadFailure" })); } try { var fileExtension = Path.GetExtension(file.FileName); var image = await _storageService.AddImageAsync(file.InputStream, fileExtension); var faces = await _cognitiveService.UploadAndDetectFaces(image.ImagePath); await _storageService.AddMetadataAsync(image, faces); } catch (Exception e) { return(RedirectToAction("Index", new { value = "uploadFailure" })); } return(RedirectToAction("Index", new { value = "uploadSuccess" })); }