added upload function and error handling