//[ValidateAntiForgeryToken] public async Task <List <string> > GetAllImage() { string userId = Request.Query["userId"]; BlobServices blobService = new BlobServices(); return(await blobService.GetAllImageFromContainerAsync(userId)); }
public async Task <string> UploadProfilePicAsync(ImageModel imageModel) { try { ApplicationUser user = await checkUserExistAsync(imageModel.Id); if (user != null) { string sasKey = Startup.Configuration.GetConnectionString("BlobSASkey"); BlobServices blobService = new BlobServices(); user.ProfilePictureImage = await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(imageModel.ImageBase64), imageModel.Id); await _userManager.UpdateAsync(user); return(user.ProfilePictureImage + sasKey); } else { return(null); } } catch (Exception e) { return(null); } }
public async Task <IActionResult> UploadMultiplePicAsync(IFormFile file) { bool isSavedSuccessfully = false; string id = Request.Headers["UserId"]; string url = ""; string sasKey = Startup.Configuration.GetConnectionString("BlobSASkey"); string error = ""; if (id != null) { try { BlobServices blobService = new BlobServices(); //foreach (var file in files) //{ //Save file content goes here if (file != null && file.Length > 0) { using (var fileStream = file.OpenReadStream()) using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); var fileBytes = ms.ToArray(); url = await blobService.UploadImageToBlobStorageAsync(fileBytes, id); isSavedSuccessfully = true; } } } catch (Exception ex) { error = ex.ToString(); isSavedSuccessfully = false; } } if (isSavedSuccessfully) { return(Json(new { ImageURL = url + sasKey })); } else { return(Json(new { Message = error })); } //BlobServices blobService = new BlobServices(); //List<string> uploadedUri = new List<string>(); //foreach (var image in imageModel.ListOfBase64) //{ // uploadedUri.Add(await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(image), imageModel.Id)); //} //return uploadedUri; }
//[ValidateAntiForgeryToken] public async Task <bool> ChangeStorage(string userId, bool state) { BlobServices blobService = new BlobServices(); var s = BlobContainerPublicAccessType.Blob; if (!state) { s = BlobContainerPublicAccessType.Container; } return(await blobService.changeContainerState(userId, s)); }
//[ValidateAntiForgeryToken] public async Task <List <string> > GetAllImageSingleUser() { string userId = Request.Query["userId"]; BlobServices blobService = new BlobServices(); if (await blobService.getContainerState(userId) == BlobContainerPublicAccessType.Container) { return(await blobService.GetAllImageFromContainerAsync(userId)); } else { return(null); } }
public HttpResponseMessage UploadImage(ImageModel content) { try { ResultResponseModel result = new ResultResponseModel(); string url = new BlobServices().UploadPhoto(content.pPhotoEncoded, content.pFileName); _db.UpdateUserPhoto(content.pUserId, url); result.Result = content; result.Error = new { Error = 200, ErrorMessage = "Ok" }; return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (ArgumentNullException) { ResultResponseModel objresult = new ResultResponseModel(); objresult.Error = new { Error = 400, ErrorMessage = HttpStatusCode.BadRequest }; return(Request.CreateResponse(HttpStatusCode.BadRequest, objresult)); throw new HttpResponseException(HttpStatusCode.BadRequest); } catch (EntityCommandExecutionException e) { ResultResponseModel objresult = new ResultResponseModel(); objresult.Error = new { Error = 5004, ErrorMessage = "Device o Customer No Encontrados" }; return(Request.CreateResponse(HttpStatusCode.BadRequest, objresult)); throw new HttpResponseException(HttpStatusCode.BadRequest); } catch (Exception e) { ResultResponseModel objresult = new ResultResponseModel(); objresult.Error = new { Error = 406, ErrorMessage = e.Message }; return(Request.CreateResponse(HttpStatusCode.NotAcceptable, objresult)); throw new HttpResponseException(HttpStatusCode.NotAcceptable); } }
//[ValidateAntiForgeryToken] public async Task <string> UploadPictureAsync([FromBody] ImageModel imageModel) { BlobServices blobService = new BlobServices(); return(await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(imageModel.ImageBase64), imageModel.Id)); }
//[ValidateAntiForgeryToken] public async Task <BlobContainerPublicAccessType> GetStorageState(string userId) { BlobServices blobService = new BlobServices(); return(await blobService.getContainerState(userId)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Register(UserViewModel model, string returnUrl = null) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Name = model.Name, Reknown = model.Reknown, Bio = model.Bio, EmailConfirmed = false }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); URLShortenerService urlShortener = new URLShortenerService(); await new EmailServices().SendEmailAsync(model.Email, "Confirm your account", urlShortener.ShortenIt(callbackUrl), EmailServices.EmailType.Register); ApplicationRole mRole = null; if (model.ApplicationRoleId != null) { mRole = await _roleManager.FindByIdAsync(model.ApplicationRoleId); } ApplicationRole applicationRole = mRole != null && mRole.Name.Equals("Admin") ? mRole : await _roleManager.FindByIdAsync(_roleManager.Roles.Single(r => r.Name.Equals("User")).Id); if (applicationRole != null) { IdentityResult roleResult = await _userManager.AddToRoleAsync(user, applicationRole.Name); if (roleResult.Succeeded) { BlobServices bs = new BlobServices(); if (user.ProfilePictureImage != null) { user.ProfilePictureImage = await bs.UploadImageToBlobStorageAsync(Convert.FromBase64String(model.ProfilePictureImage), user.Id); } await _userManager.UpdateAsync(user); string message = "User created a new account with password."; _logger.LogInformation(3, message); return(Ok(Json(new { message = message, user = user }))); } } } AddErrors(result); } // If we got this far, something failed, redisplay form return(BadRequest(Json(new { messages = errors }))); }