In `upload_file` function, what if `read_to_end` fails? I think it will result in sending a partial file content. It should be failed in that case, however.