How to put ellipses in the middle of text like native file input

How can I do this? I am builidng my own file input (1st one) by using a button and hidden file input and want to replicate the text overflow behavior from the native file input (2nd one).

enter image description here

I’ve seen soultions like this. I tried it and it works, but it feels rather strange to split the text like that.

enter image description here