Ejemplo n.º 1
0
        public List <Uri> UploadImagesFromFiles(IEnumerable <Stream> images)
        {
            int index = 0;

            foreach (Stream stream in images)
            {
                DateTime time = DateTime.Now;
                using (var fileStream = new FileStream(Path.Combine(_hostingEnvironment.ContentRootPath, "Pictures", $"ImportPicture-{time.Year}-{time.Month}-{time.Day}-{time.Hour}-{time.Minute}-{time.Second}-{index}.png"), FileMode.Create, FileAccess.Write))
                {
                    stream.CopyTo(fileStream);
                }
                index++;
            }

            return(_parent.UploadImagesFromFiles(images));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UploadImages([FromForm] IEnumerable <IFormFile> images)
        {
            var listOfImageStreams = new List <Stream>();

            foreach (var image in images)
            {
                var imgStream = new MemoryStream();
                await image.CopyToAsync(imgStream);

                listOfImageStreams.Add(imgStream);
            }

            var result = _imageCloudService.UploadImagesFromFiles(listOfImageStreams);

            return(StatusCode((int)HttpStatusCode.OK, result.ToArray()));
        }
Ejemplo n.º 3
0
        private List <string> BuildPictureUrlList(List <string> pictureUrls, List <IFormFile> pictureFiles)
        {
            List <string> tempList = new List <string>();

            if (pictureUrls != null)
            {
                tempList.AddRange(pictureUrls);
            }

            if (pictureFiles != null && pictureFiles.Count > 0)
            {
                List <Uri> uris = _imageCloudService.UploadImagesFromFiles(
                    pictureFiles
                    .Select(x => x.OpenReadStream())
                    .ToList()
                    );
                tempList.AddRange(uris.Select(x => x.ToString()));
            }

            return(tempList);
        }