json - 从 API 获取 image_base64 的 JSON 对象并将其转换为图像
问题描述
我正在尝试使用 GET 方法获取 base64 API 响应并显示图像。
api调用和fetch
方法如下:
export default class CardCall extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
dataSource: null,
};
}
componentDidMount() {
return fetch(`${apiUrl}/card/image?cardtoken=token`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
"onmo-api-auth": apiAuth,
},
})
.then((response) => response.json())
.then((responseJson) => {
console.log("This should be the card image", responseJson)
this.setState({
isLoading: false,
dataSource: responseJson.dataSource
});
})
.catch((error) => {
console.log(error);
});
}
然后调用将base64渲染成图像如下
< Image source={{ uri: base64.decode(this.state.dataSource) }} />
API 响应是:
cvv: "cvv"
emboss_name: "name"
epan: "pan"
expiry: "expire"
image_base64: "iVBORw0KGgoAAAANSUhEUgAAAdYAAAEjCAIAAAAAJ7enAACAAElEQVR42uzdd3xVRfo/8EsKXWmhpHdC7wKi0kXpnXTSC71D6EXpEAgp9C4gSBEQxIJ0qQn43Z99XV3XtQJKhxTymzlz…"
token: token
我已经尝试映射和提取身体但无济于事,请你帮帮我
解决方案
推荐阅读
- blockchain - ERC721 - tokenURI 中提及的元数据资产的真实性
- mongodb - 从猫鼬聚合管道中的数组数组中获取单个数组
- ruby-on-rails - Rails ActiveStorage/S3 无法在生产环境中工作
- php - GetText 0 复数
- sql - 基于多个条件的 SQL 搜索产品(如果属性='长度'则值>70,如果属性='权重'则值>3)
- hana - 无法通过 Eclipse Neon 插件连接到 SAP HANA Cloud
- python - 为什么我在将新字段附加到数据帧时得到所有 NAN?
- python - 反向传播实现 - 如何在矩阵上应用链式法则
- c# - 获取 Unity3D 中脚本的类型
- php - 当所有变体都缺货时,显示在 WooCommerce 可变产品上售罄