简体   繁体   中英

S3 file uploaded is getting corrupted

I have some code that uploads filestream to s3 bucket. One of my customer is having some issues but I'm having trouble reproducing it on my end. Upon upload, their filesize remains at 0 bytes. This does not occur every time. Seems very sporadic.

在此处输入图像描述

using (var webclient = new WebClient())
{
    using (MemoryStream stream = new MemoryStream(webclient.DownloadData(uri)))
    {
        using (var client = new AmazonS3Client())
        {
            PutObjectRequest request = new PutObjectRequest
            {
                BucketName = bucketName,
                Key = GetObjectKey(fileName, companyAccountId),
                InputStream = stream
            };

            if (height > 0)
                request.Metadata.Add("x-amz-meta-height", height.ToString());

            if (width > 0)
                request.Metadata.Add("x-amz-meta-width", width.ToString());

            var response = await client.PutObjectAsync(request);
        }
    }
}

Any help or suggestion would be greatly appreciated to help determine why a file being uploaded is remaining at 0 bytes.

Is there anything else that could be consuming the inputStream and leaving the position at the end? I have had a similar problem before and solved the problem by ensuring the stream is at the start by either

stream.Seek(0, SeekOrigin.Begin);

or

stream.Position = 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM