The issue I am having is that I set maxBufferSize in the
basicHttpBinding both on client and the service side to 1MB (1048576) so I did with the lenght of the buffer here in the above code, but it seems the maxBufferSize value has nothing to do with the length of data chunk read in each loop here since
binaryContent.Read reads always 4096 bytes causing data corruption at the end.

I could set the buffer size back to 4096 but I would like to know if it is possible to read more bytes than 4KB block at a time.

Re: WCF uploading binary data using streamed transfer

Thanks for the answer. I found that 4KB is a default buffer size for reading a stream with Read method. The default buffer size can be defined when the stream object is constructed, but in this case the uploadFile
control does not give me any option to set a default buffer size... Of course it can be done using some sort of conversion of the stream after the file is uploaded... but I actually come up with a workaround solution to my problem:

For now, I use help from a temp 1MB buffer (an additional byte array) that collects all the 4KB blocks until it is full, and then I flush that temp buffer to
database. This little adjustment improves performance significantly even if it is a “quick and dirty” solution...