& symbol within filename doesn’t working

Hi I was working with dropzone a javascript library used to upload files by drag and drop. I have noticed while file upload there are few files which contains reserved character &. It was causing issue and not including the path after the & symbol or space into the path or my anchor tag, which breaks the stuff. You can read more about unsafe characters here

I didn’t get first time as it works with other files name who doesn’t contains & symbol. After some time I realized the cause of issue. I did some research how to fix but didn’t get satisfactory solution. Then I decided to encode the url, because once the url encoded it won’t encode & symbol as well. So that works like charm for me.

I just encode the url and add that url to my anchor tag. Here the code example

var url="mukeshsalaria & learnsharecorner.png";
var path = encodeURI(url); 
<a href=" + path + ">encoded path of image</a>

I hope it will help you guys.


Posted by | View Post | View Group