Rather than copy / pasting this block, can you make a helper function for it and use it in both upload and download?