I hava a REST service to download and upload binary files. I enabled WCF Streaming on the service (read
here), and streaming seems to work fine for downloading big files (up to 2 GB) using the HttpClient. I check memory lvels on the setser and it doesn't change while the file is downloaded, which means the server is streaming the
bytes instead of buffering the whole file.
Now, I'm trying to upload a file using the HttpClient using this code:
string filePath = @"d:\BigFile.rar";
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
long length = fs.Length;
HttpContent content = HttpContent.Create(fs, "application/octet-stream", length);
var response = webClient.Post("Files/filenmae", content);
response.EnsureStatusIsSuccessful();
When I run that code I can see the memory going up in the client. After a few seconds, when the whole file is buffered in the client, I start seeing activity on the server. If the file is bigger than 1GB I get an excepton on the client.What I'm I missing
here?
oscarmorasu
0 Points
3 Posts
Upload big files as a Stream using HttpClient
Aug 07, 2010 02:28 AM|LINK
Hi,
I hava a REST service to download and upload binary files. I enabled WCF Streaming on the service (read here), and streaming seems to work fine for downloading big files (up to 2 GB) using the HttpClient. I check memory lvels on the setser and it doesn't change while the file is downloaded, which means the server is streaming the bytes instead of buffering the whole file.
Now, I'm trying to upload a file using the HttpClient using this code:
string filePath = @"d:\BigFile.rar"; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); long length = fs.Length; HttpContent content = HttpContent.Create(fs, "application/octet-stream", length); var response = webClient.Post("Files/filenmae", content); response.EnsureStatusIsSuccessful();When I run that code I can see the memory going up in the client. After a few seconds, when the whole file is buffered in the client, I start seeing activity on the server. If the file is bigger than 1GB I get an excepton on the client.What I'm I missing here?