I share it once and it gets uploaded to Sharepoint (as `foo.jpg`). This happens even if you're just sharing a funny image in a private message. It gets uploaded to Sharepoint. Ugh.
Anyway, let's say I share the same image again. Teams says "hey do you want to overwrite `foo.jpg`, or keep the existing one?" I select keep. Teams now creates `foo-1.jpg`.
We're already off to a bad start, but bear with me. Here's where it gets amazing:
1. I share `foo.jpg` a third time.
2. Teams says "Do you want to overwrite or keep?" I select keep.
3. Teams then again asks "Do you want to overwrite or keep?", because `foo-1.jpg` is taken. I select keep.
4. Teams tries to create `foo-2.jpg`. Return to step #2 until an unused integer is found.
That chain of dialogs can continue for a while for common file names on large teams.