public async Task <IActionResult> UploadPicture(UploadPictureViewModel model, List <IFormFile> files)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.GetUserAsync(User);

            var profile = _context.Profiles.Where(s => s.Id == user.ProfileId).SingleOrDefault();

            foreach (var formFile in files)
            {
                model.AvatarImage.Add(formFile);
                if (formFile.Length > 0)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        var file = model.AvatarImage[0];
                        await file.CopyToAsync(memoryStream);

                        profile.AvatarImage = memoryStream.ToArray();
                    }

                    await _context.SaveChangesAsync();
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> UploadPicture()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var model = new UploadPictureViewModel
            {
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult UploadPicture(int id, UploadPictureViewModel model)
        {
            using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString()))
            {
                var streamContent = new StreamContent(model.PictureFile.OpenReadStream());
                streamContent.Headers.Add("Content-Type", model.PictureFile.ContentType);
                streamContent.Headers.Add("Content-Disposition", $"form-data; name=\"file\"; filename=\"{model.PictureFile.Name}\"");
                content.Add(streamContent, "file");

                var msg = GetHttpClient().PutAsync($"{baseUploadAddr}/replace/{model.Id}", content).Result;

                msg.EnsureSuccessStatusCode();
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
        public ActionResult UploadPicture(UploadPictureViewModel model)
        {
            if (ModelState.IsValid)
            {
                var sourceName   = model.Picture.FileName;
                var sourceStream = model.Picture.InputStream;

                var blobInfo = _blobService.Upload(
                    sourceName,
                    sourceStream,
                    User.Id
                    ).GetInfo();

                return(Json(new
                {
                    blob = blobInfo,
                    thumbnail = _blobService.GetThumbnailEndpoint(blobInfo.Name, "preview", model.PreviewThumbWidth, model.PreviewThumbHeight)
                }));
            }

            return(JsonError(ModelState));
        }
Exemplo n.º 5
0
 public UploadPicture(UploadPictureViewModel vm)
 {
     InitializeComponent();
     BindingContext = vm;
 }