c#-将图像作为内存流上传到AWS S3

我正在研究一个响应Http POST并接受带有IFormFile的表单的端点,该表单应该是图像(jpg / png)。 目标是将图像格式化为WebP In Memory,然后将其传递到MemoryStream并将其上传到AWS S3存储桶。现在,我调试了代码,一切似乎都正常运行,但是图像没有上传。 以下是相关的代码段: ImageFormaterClass

foreach (var image in images)
            {
                // validate image format
                string[] allowedImageTypes = new string[] { "image/jpeg", "image/png", "image/jpg" };
                if (!allowedImageTypes.Contains(image.ContentType.ToLower()))
                {
                    resultList.Result = false;
                    resultList.ErrorMessage = "Image format not accepted. Accepted formats: jpeg / jpg / png";
                    return resultList;
                }

                // convert pic in Main Memory
                MemoryStream memoryStream = new MemoryStream();

                using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                {
                    imageFactory.Load(image.OpenReadStream())
                    .Format(new WebPFormat())
                    .Quality(80)
                    .Save(memoryStream);
                }

                resultList.ProcessedPictures.Add(memoryStream);
            }

此过程的输出转发到AWS S3 Uploader类 AWsImageUploader

// image is type MemoryStream
foreach (var image in imageProcessingResult.ProcessedPictures)
            {

                string guid = Guid.NewGuid().ToString();
                image.Position = 0;
                byte[] memString = image.GetBuffer();

                    try
                    {

                        var request = new Amazon.S3.Model.PutObjectRequest
                        {
                            BucketName = bucketName,
                            Key = "./assets/images/" + guid + ".webp",
                            InputStream = image,
                            ContentType = "image/webp",
                            CannedACL = S3CannedACL.PublicRead
                        };
                        var rez = await s3Client.PutObjectAsync(request);
                    } catch (Exception e)
                    {
                        imageUploadResult.Result = false;
                    }

            }

没有异常被抛出...可能是什么?紧急求救

评论