javascript - ReactJS, rendering base64 string in <img> tag gives error ERR_INVALID_URL -


i attempting render few server generated images (matplotlib graphs specific) reactjs module without saving files on server. approach took use base64 generate image string.

when time comes render image in react component, use:

render(){   const chart1 ="data:image/png;base64," + this.props.matchplot1   return <div>       <img src={chart1} />   </div> } 

but unfortunately greeted with:

get data:image/png;base64,b'iv... ...cyii=' net::err_invalid_url

in javascript console. understand, somewhere along line the resulting html thinks i'm specifying external hyperlink, when in fact want use actual decoded base64 string image. have seen solutions angular (img ng-src="") , react-native (image /), haven't found solution reactjs.

i using reactjs 15.1.0 , jsxtransformer v0.13.3 client-side rendering. webserver, if relevant, flask python3.

any help, or alternate strategy produce image without saving copy on server appreciated! (ps. i've used d3 draw graphs of data client-side, svgs there many points , performance terrible. i've converting svgs canvas it's more work hoping deal right now)

edit: should have looked @ string more closely. server response ajax request , in python3 (maybe 2?) bytestring not json serializable. converted str str(plots[0]). accidentally added b'{string}' wrapper around base64 object, evidenced in console response. guess syntax enough through chrome off. that, , red herrings angular , react-native solutions led me believe react problem when fact it's pythong string problem. it's working now, , appreciate input.

without full string, it's hard tell certainty wrong.

however, think might've found issue:

get data:image/png;base64,b'iv... ...cyii=' net::err_invalid_url

based on above error you're getting, looks might missing = @ end of uri, depending on length.

try changing ends cyii== , not cyii= seems currently.

alternatively, variable matchplot1 might somehow incorrect. if has //, make sure escape comment.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -