Refactor (and extract) upload_to_pivnet

* and backfill tests

[#80164088]