1

we have data coming from another application(DB) like below image file has been stored like

@1="< img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...">"

var data = @1 DownloadCode();

i want to download file image file. I am newbie in JS.

6
  • Not too sure ! do you want a physical image? As I can see you have base64 encoded image. So if you want the physical image you need to decode it. Commented Sep 5, 2017 at 11:05
  • i tried this code. i need src of image in js variable ........var m, urls = [], str = '<img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgA...">', rex = /<img[^>]+src="?([^"\s]+)"?\s*\/>/g; while ( m = rex.exec( str ) ) { urls.push( m[1] ); } console.log( urls ); Commented Sep 5, 2017 at 11:05
  • The code looks good. and putting everything into an array. you just need to take it from an array ... If you are not using multiple Images avoid array and put into variable Commented Sep 5, 2017 at 11:11
  • my string is like str = '<img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gAcU29mdHdhcmU6IE1p......hl//2Q">' this reg ex is not working for me. img tag is not closed properly. i think. It is able to render correct. Commented Sep 5, 2017 at 11:19
  • Please Check my answer and let me know if it works for you. Commented Sep 5, 2017 at 11:21

1 Answer 1

1

Here how you should do it

var str = '<img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgA...">';

var regex = /<img.*?src="(.*?)"/;
var src = regex.exec(str)[1];

console.log(src);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.