Fix some encoding bugs when sending large files