Express.JS res.sendfile for special characters

I came across a strange issue this week while working on whereby if I ran:

res.sendfile(filename) 

It would work for the majority of my music library I had scanned, but it would not work for ones containing a % (percentage) character. After filing an issue an being pointed in the right direction I found it was linked to . The solution was simple, change my code to be this:

res.sendfile(encodeURIComponent(filename)) 

And boom, it worked. From a brief look into documentation this could also occur with the following characters: ? : @ & = + $ #.

this issue

Benjamin Kaiser

Benjamin Kaiser

Software Engineer working on the SharePoint team at Microsoft. I'm passionate about open source, slurpess, and Jesus.
Gold Coast, Australia

Post Comments