You can make a "form" to hold the spray foam out of several layers of newspaper. It will be strong enough to hold the foam in place (just be careful to not over-fill; that stuff expands like crazy!) and you can peel off the newspaper when cured.

Not easy, and can be REAL messy, but if it's in an area where appearance isn't a priority is worth a try.