關於上一個問題here我從社區獲得幫助以將生成的base64字符串設置爲src屬性,但是,圖像或圖像缺少圖像的底部。請看下面的圖片。爲什麼我的base64字符串只顯示我的照片的一部分?
下面是我使用的設置圖像內容的代碼。如何讓圖像的其餘部分顯示?
import React from 'react';
import axios from 'axios';
import * as settings from './settings';
export default class Post extends React.Component {
constructor(){
super();
this.state = {
profileImage:'img/loading.gif'
};
}
componentDidMount(){
if(this.props.post.PostImageId != "00000000-0000-0000-0000-000000000000"){
// get post image data
_rvw.getImage(this.props.post.PostImageId)
.then((res)=>{
this.setState({
postImage: "data:" + res.headers["content-type"] + ";base64," + res.data
});
});
}
else //no image
{
this.setState({
postImage: "img/no-image.png"
});
}
}
getImage(id){
let config = {
headers:{
'Content-Type': 'application/json',
'Accept':'application/json',
'Authorization':'Bearer ' + localStorage.token
}
};
return axios.get(settings.baseUrl()+'/mediacontent/get/'+id,config);
}
render(){
return (<div className="image">
<img ref="postMedia" src={this.state.postImage} />
</div>);
}
}
全部部件可以發現here。
首先檢查您收到的數據是否完整。 – zerkms
不相關的,但仍然:btw,'this.props.post.ProfileImageId!= null'檢查可能是多餘的。 – zerkms
我仔細檢查了大小,它是正確的。 azure上的blob是289.9kb,我從http響應中收到290kb。 – chesco