【发布时间】:2017-09-15 02:26:46
【问题描述】:
在上一个问题here 上,我收到了社区的帮助,将生成的 base64 字符串设置为 src 属性,但是,图像缺少图像的底部。请看下图。
下面是我用来设置图像内容的代码。如何让图像的其余部分显示?
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找到。
【问题讨论】:
-
先检查收到的数据是否完整。
-
无关紧要,但仍然:顺便说一句,
this.props.post.ProfileImageId != null检查可能是多余的。 -
我仔细检查了尺寸,它是正确的。 azure 上的 blob 为 289.9kb,我从 http 响应中收到 290kb。
-
等等,二进制数据的blob是289k?还是 289kb 的 base64?
标签: javascript c# azure reactjs azure-blob-storage