Call endUpload() in finally block of fail handling (#14677).

Change-Id: I0b5976abf0d8804e8cd34c5dd489da8617ef89f1