Let me start by saying I have not used background tasks, so I read the documentation and I think you just need to layer one more step by creating a callable function that returns a task object that is created by running your decorated ‘@anvil.server.background_task’ function. The result of this background task function should return the media object you want.
When task.is_completed() becomes True, the value of task.get_return_value() will be the media object.