added an error check before file upload