1

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.

Laura
  • 97
  • 9
  • 1
    Possible duplicate of [How to replace all occurrences of a string in JavaScript](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript) – Reactgular Jul 11 '19 at 08:05
  • Try `.replace(/\\/g, '/')` – ischenkodv Jul 11 '19 at 08:06
  • Hello @ischenkodv, thanks a lot for your reply. that didn't workd with me – Laura Jul 11 '19 at 08:47
  • Hello Sir @Reactgular, thanks for your reply. But that link can't resolve my problem. All the examples are for string not containing slashs. – Laura Jul 11 '19 at 09:34
  • @Laura there is a big difference between `'..\assets\dist\upload\avatar.jpg'` and `'..\\assets\\dist\\upload\\avatar.jpg'` in JavaScript. – Reactgular Jul 11 '19 at 09:39
  • Yes Sir, I totally agree, but in that thread I didn't found an example how convert `'..\assets\dist\upload\avatar.jpg'` to `'../assets/dist/upload/avatar.jpg'`. Only I found how convert `'..\\assets\\dist\\upload\\avatar.jpg'` to `'../assets/dist/upload/avatar.jpg'`. Have you please any suggestions?. Big thanks Sir. – Laura Jul 11 '19 at 09:43
  • @Laura open the JavaScript file in a text editor and manually add an extra `\\` to each string that uses only one of them. – Reactgular Jul 11 '19 at 10:01
  • Ok Sir @Reactgular, thanks, but what about case of using dynamic path, so I can't made change manually ?. I have to convert directly without manual intervention ?. – Laura Jul 11 '19 at 12:52

1 Answers1

5

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

Saria Essid
  • 1,240
  • 1
  • 11
  • 16