While trying to pull images from Reddit using its json API for an app I ran into a strange error,
Using the extracted image url, a few images would load perfectly but others would fail.
After some debugging, I found the issue and decided to post it here, in case someone else faces a similar issue
Digging a little deeper, it is clear that the image url supplied by the reddit api is incorrect. Attempting to open the url in the browser gives the error:
URI signature match failed.
Consider the following url supplied by reddit:
It appears that their json API escaped the ampersand in the url.
& with a
& will return the correct image url.
the image from that url now loads:
*As of 14-2-2017, this issue still persists.
So this can be fixed by replacing all instances of & with & which can be done with regex in all most every language.
Since I’m working with Angular at the moment, I wrote a simple ts fix, that looked something like this:
let oldURL: string = "https://i.reddituploads.com/3ac211e88e214eff9113fa4ed2f3635e?fit=max&h=1536&w=1536&s=b545edd8de65c9bb18bcca7d38aad0b7";
let newURL: string = oldURL.replace(/&/g,"&");
/&/ that is to make sure multiple occurrences of the string matching are replaced.
Hope this helps!