Upload image with mention (@username) as first characters returns empty response with error "Could not find file username"


I’m using the REST api and as the title says, whenever I try to upload an image with the tweet “@username here is my image”, it returns an empty response and error “Could not find file username”. It looks like it’s getting confused with the media[] => @{$image};type=image/jpeg;filename={$image}.
When I set the media and then change the tweet to “.@username here is my image” (note the period as the first character), this works.