Your method upload
most likely breaks the PDF contents because it treats it as text:
You use a StreamReader
to read the PDF file. That class
Implements a TextReader that reads characters from a byte stream in a particular encoding.
This implies that while reading the file bytes, the class interprets them according to that particular encoding (UTF-8 in your case because that's the default). But not all byte combinations do make sense as UTF-8 character combinations. Thus, this reading already is destructive.
You partially make up for this interpretation by re-encoding the characters according to UTF-8 later:
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
but as said before, the initial interpretation, the decoding as a UTF-8 encoded file already has destroyed the original file unless you were lucky enough and all the byte combinations made sense as UTF-8 encoded text.
For binary data (like ZIP archives, Word documents or PDF files) you should use the FileStream
class, cf. its MSDN information.