Short answer is you can't. Factory Reset wipes the entire phone, including media, personal files, apps, data, etc. Everything.
You can back up your media and files to a computer or use a 3rd party back up app like Titanium to back things up, or if you have a phone that supports a manufacturer-specific solution, like Samsung's Smart Switch, you can back things up there, too.
Then, you can either initiate the factory reset from your phone's settings or from the Recovery menu. This document from T-Mobile explains how to do both, and should apply to the S8+ and non-T-Mobile phones as well.
https://support.t-mobile.com/docs/DOC-34251
Jut remember... Factory reset means ALL DATA will be wiped. So don't do that unless you've backed things up.
You can also try to uninstall whatever you installed in Safe Mode and run a malware/adware detector if that's what got in. Here's how to run in Safe Mode.
https://support.t-mobile.com/docs/DOC-34283