2017-02-01 7 views
1

私はデータベースに画像を挿入しても、私はデータベースからサーバとreactjsに画像を受信して​​いますが、私はそれがバイナリデータを受信して​​います。 しかし、どのようにして私はバイナリデータを反応してイメージに変換しますか?どのようにreactjsの画像にバイナリデータを変換する

あなたがバイナリデータを持っている場合、このような画像に変換し、 ReactJSに関連していない画像にバイナリデータを変換する
class Pre extends React.Component{ 
    constructor(props){ 
    super(props); 
    this.state={ 
     post:[] 
    }; 

    } 


componentDidMount(){ 
    let self = this; 
    axios.get('http://localhost:8080/images') 
    .then(function(data) { 
     //console.log(data); 
     self.setState({post:data.data}); 
     }); 
    } 


    render(){ 

console.log(this.state.post); 
    return(
    <div className="w3-container"> 


    <p className="addboard"> <Link className="linkpre" to="/createstudent I"> 
     <button className="addbutton" type="button"><h1>+</h1></button></Link></p> 


     {this.state.post} 

)} 
)} 

</div> 

    ); 
    } 
} 
export default Pre; 

答えて

1

<img src={`data:image/jpeg;base64,${binary_data}`} /> 
関連する問題