Handle all possible errors when uploading files (see #5934)