示例#1
0
        public async Task <ActionResult> UploadAsync(IFormFile file)
        {
            if (file != null)
            {
                var image   = file.OpenReadStream();
                var imageId = await _imageStore.StoreImageAsync(image);

                return(RedirectToAction(nameof(Display), new { imageId = imageId }));
            }

            return(View());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public async Task <string[]> StoreImagesAsync(IEnumerable <IFormFile> files)
        {
            var resultCollection = new List <Option <string, Error> >();

            foreach (var formFile in files)
            {
                if (formFile.Length <= 0)
                {
                    continue;
                }

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

                    resultCollection.Add(
                        await _imageStorageService.StoreImageAsync(
                            formFile.FileName,
                            memoryStream.ToArray()));
                }
            }

            return(resultCollection.Values().ToArray());
        }