0

I am using presigned URLs to let our C# application upload directly from the user location to our S3 bucket. I exactly used the .NET sample code from the AWS documentation:

https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html

private static void UploadObject(string url)
        {
            HttpWebRequest httpRequest = WebRequest.Create(url) as HttpWebRequest;
            httpRequest.Method = "PUT";
            using (Stream dataStream = httpRequest.GetRequestStream())
            {
                var buffer = new byte[8000];
                using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    int bytesRead = 0;
                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        dataStream.Write(buffer, 0, bytesRead);
                    }
                }
            }
            HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;
        }

This works well for small image files (<1MB) but often fails for larger video files (10-20 MB). I need multiple attempts before the upload succeeds, because I often get a SocketException error, saying that the connection was closed by the remote host.

Does anyone know how to deal with this issue?

Thank you for your help!

sanc
  • 21
  • 2
  • 1
    How long does it take before failure occurrs. If it is around 30 seconds you may need to increase the default 30 second timeout. – jdweng Feb 20 '21 at 11:52
  • Thanks for your help! It indeed occurs around 30 seconds. Do I need to set the timeout on the S3 side? I thought the default timeout for httpwebrequest was already 100 seconds. – sanc Feb 20 '21 at 12:40
  • You are right. Read SystemDll comment at following : https://stackoverflow.com/questions/37466847/dynamodb-causing-lambda-timeout – jdweng Feb 20 '21 at 16:21
  • In Net a database command timeout default to 30 seconds. – jdweng Feb 20 '21 at 16:39

0 Answers0