Fixing the "URI signature match failed" error while displaying Reddit Images

Shawn Rebello

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.

Solution

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:


Replacing the & amp ; with a & will return the correct image url.


*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:


 let oldURL: string = "https://i.reddituploads.com/3ac211e88e214eff9113fa4ed2f3635e?fit=max&h=1536&w=1536&s=b545edd8de65c9bb18bcca7d38aad0b7";
 let newURL: string = oldURL.replace(/&/g,"&");


Note the g after /&/ that is to make sure multiple occurrences of the string matching are replaced.
Hope this helps!

Shawn Rebello / Author & Editor

Shawn Rebello is an engineering student who likes learning new languages, tools, libraries or frameworks. When he is not coding, he binge watches TV shows and spends time on Wikipedia and Reddit.

2 comments :

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

    ReplyDelete

Leave a comment here!