Add proper error handling when uploading a file