Fix nil pointer error if an error occurs in preprocessUpload()

If an error occurs in preprocessUpload(), the cleanup could panic with a nil pointer. This fixes that.