Added error handleing to upload file function