Fix upload code.

1. remove the file if any error occurred during uploading.