Fixed locking and cleaned up error handling in FileUploadHandler (#10569)

Change-Id: I6ed72b866ee4ca28957726f8dbe0bda6316e8685