Cannot close stream until all bytes are written aws s3 upload image

c# amazon-s3

183 观看


1977 作者的声誉

I am using below code

using (AmazonS3Client s3client = 
          new AmazonS3Client( ConfigurationManager.AppSettings["s3accesskey"], 
    PutObjectRequest putObjectRequest = new PutObjectRequest
        BucketName = rootBucket,
        Key = key,
        InputStream = content


It is throwing below error

Cannot close stream until all bytes are written.

please advise

作者: Md. Parvez Alam 的来源 发布者: 2017 年 12 月 27 日

回应 2


0 作者的声誉

This happens because the stream is at the end. Just set the position of your stream back to 0 and it'll work.

Hope that helps!

作者: user9244629 发布者: 2018 年 4 月 19 日


7284 作者的声誉

it seems you can also get this same exception intermittently when S3 times out while uploading. you can fix that by increasing the timeout, e.g.:

new AmazonS3Client( ConfigurationManager.AppSettings["s3accesskey"],
                    new AmazonS3Config { Timeout = TimeSpan.FromMinutes(30),
                                         ReadWriteTimeout = TimeSpan.FromMinutes(30) } )
作者: gordy 发布者: 2018 年 8 月 21 日