C#C
C#3y ago
8 replies
Srejon Khan

❔ HttpClient - Error while copying content to a stream - AWS S3

Hello,

I've been trying to upload file to AWS S3's presigned URL using POST method. All the presigned URL is coming from a third-party service and I can upload files without any problem from console application.

The problem arises when error/exception happens on the AWS side. For example, if I'm trying to upload a file larger than the size limit that is defined for that presigned URL, the response gives an error in XML format describing the problem. In such case, from console side, my request can't complete to read the error messages. Rather, it throws
Error while copying content to a stream
. Excepted outcome is to read the response from console.

Here is the code - https://gist.github.com/SrejonKhan/3259dbc64d07cb07fb3e5e33f739e891

---Exception---
Message: Error while copying content to a stream.
Stack Trace: https://elmah.io/tools/stack-trace-formatter/91b95889b9a140d39951bfd9158afc0c/

---Inner Exception---
Message: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
Stack Trace: https://elmah.io/tools/stack-trace-formatter/cfa9beae842a4981a9ce442e3acc873d/

---Inner Exception---
Message: An existing connection was forcibly closed by the remote host.

Workaround: If I try in HTTP/1.0 rather that HTTP/1.1, it works even in server side exception. But, it's terribly slow!
Was this page helpful?