0

I'm creating a web-playlist with Amplitude.js, and am having problems generating the urls for some of the song files. Specifically, when I try to encode a string with the '「 ' and '」' characters, it does not return the correct url. When I manually inspect the file in my local directory, it says this is the url:

'/data/album0/04%20「%20P%20H%20Y%20S%20A%20」-%20w0nd3rful.mp3'

screen shot of address ^Screen shot of address when I open the .mp3 file in my directory (browser: google chrome)

How do I get the correct encoding and what accounts for this discrepancy?

let songToGet = 'data/album0/04 「 P H Y S A 」- w0nd3rful.mp3'
let encoded = encodeURI(songToGet)
let decoded = decodeURI(encoded)

console.log(decoded === songToGet)
ANimator120
  • 2,556
  • 1
  • 20
  • 52
  • 2
    not replicable, it's the same address `data/album0/04%20%E3%80%8C%20P%20H%20Y%20S%20A%20%E3%80%8D%20-%20w0nd3rful.mp3` === `data/album0/04 「 P H Y S A 」 - w0nd3rful.mp3` after browser decode, maybe you don't understand how `url encode` works? – Flash Thunder Jul 26 '20 at 07:58
  • I'm running a local server, any chance it has something to do with that? – ANimator120 Jul 26 '20 at 07:59
  • But with what? You need to clarify your problem. URL decoding/encoding is on browser side, shouldn't have anything to do with server. – Flash Thunder Jul 26 '20 at 08:00
  • when I go to the file manually in my directory the address in the URL bar is /data/album0/04%20「%20P%20H%20Y%20S%20A%20」-%20w0nd3rful.mp3, is there another step I need to go through to convert data/album0/04%20%E3%80%8C%20P%20H%20Y%20S%20A%20%E3%80%8D%20-%20w0nd3rful.mp3 to that? – ANimator120 Jul 26 '20 at 08:02
  • imo the easiest way to check that it's fine is to go to https://www.google.com/search?q=data/album0/04%20%E3%80%8C%20P%20H%20Y%20S%20A%20%E3%80%8D%20-%20w0nd3rful.mp3 – Flash Thunder Jul 26 '20 at 08:02
  • @ANimator120 yes, browser changes that to the url you have given, and it's fine... and what is the problem? that PHP can't find a right file after that? PHP has problems with UTF file names on Windows. – Flash Thunder Jul 26 '20 at 08:03
  • When I try and get 'data/album0/04%20%E3%80%8C%20P%20H%20Y%20S%20A%20%E3%80%8D%20-%20w0nd3rful.mp3' as the address of the file to get I get a 404 message, however when I paste '/data/album0/04%20「%20P%20H%20Y%20S%20A%20」-%20w0nd3rful.mp3' as the address I get the file. I'm not using PHP (as far as I can tell, as in I haven't written any) – ANimator120 Jul 26 '20 at 08:13
  • @FlashThunder when I run the above snippet it returns that they are not equal – ANimator120 Jul 26 '20 at 08:23
  • What library/code is serving the static files, and what’s the filename in your filesystem (if applicable)? – Ry- Jul 26 '20 at 08:39
  • @Ry filename as copied from Finder's file information: '04 「 P H Y S A 」- w0nd3rful.mp3'. I'm running the code on a local server using atom-live-server (https://github.com/jas-chen/atom-live-server), which seems to be written in js. – ANimator120 Jul 26 '20 at 08:50
  • Some part of one of the modules involved might have a bug. The easiest way to debug that might be to try a different and more common server, like Apache or Nginx, even though it’s a bit of a hassle. Your check should be `decoded === songToGet`, not `decoded === encoded`, by the way. – Ry- Jul 26 '20 at 09:10
  • @ANimator120 for me it returns that they are equal. `console.log(decoded === songToGet)` returns `true`, so not replicable (as I said in my first comment under this post), sorry. Has nothing to do with the server, but the browser. When you run that snippet in here it shows `false`? – Flash Thunder Jul 27 '20 at 14:59

0 Answers0