Laura
Laura

Reputation: 97

Replace \ with / on image path

I get this produced path of an uploaded image:

'..\assets\dist\upload\avatar.jpg'

I'd like make it with this format.

'../assets/dist/upload/avatar.jpg'

I tried with .replace(/[\]/g, '/');

But didn't works with me.

Also, I consult this thread, but didn't resolve my problem. There isn't an example about converting back slash to forward slash.

Only it's possible if we are talking about '..\\assets\\dist\\upload\\avatar.jpg'. But, my case is '..\assets\dist\upload\avatar.jpg'.

Have you please any idea about solving that ?.

Big thanks.

Upvotes: 1

Views: 395

Answers (1)

Saria Essid
Saria Essid

Reputation: 1248

Try to made change on backend. So you have that format '..\\assets\\dist\\upload\\avatar.jpg'. On frontend try to use .replace(/[\\]/g, '/') So yo got '../assets/dist/upload/avatar.jpg'

HTH

Upvotes: 5

Related Questions