This can probably be split out into a top-level function. We should probably also have a more suitable name than `doUpload`