Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解析为从服务器接收的图像内容类型:image/bmp?_Javascript_Image - Fatal编程技术网

Javascript 如何解析为从服务器接收的图像内容类型:image/bmp?

Javascript 如何解析为从服务器接收的图像内容类型:image/bmp?,javascript,image,Javascript,Image,我从服务器接收到内容类型为:image/bmp的图像,需要在前面显示 我在客户端使用react.js,但我不知道如何解析接收到的内容 我尝试使用Base64解析器并将结果放入img.src,但没有帮助 let { data } = yield call(axios, requestConfig1); data = Base64.decode(data); const img = new Image(); img.src = data; 还尝试直接使用数据: img.src = `data:i

我从服务器接收到内容类型为:image/bmp的图像,需要在前面显示

我在客户端使用react.js,但我不知道如何解析接收到的内容

我尝试使用Base64解析器并将结果放入img.src,但没有帮助

let { data } = yield call(axios, requestConfig1);
data = Base64.decode(data);

const img = new Image();
img.src = data;
还尝试直接使用数据:

img.src = `data:image/bmp;base64,${file}`;
没有帮助。我在img标记的src属性中看到未知

我想把结果显示为img标签

我在这样的代码中看到响应

您是否尝试过:

img.src = `data:image/bmp;base64,${file}`;

参考屏幕截图,您的API将返回一个图像二进制文件,因此您应该将原始图像数据编码为base64字符串

注意:我希望您的requestConfig1具有requestType:'blob'

解决方案1:图书馆

解决方案2:使用btoa

用于避免“字符超出拉丁1范围”错误。此功能已从web标准中删除,但仍受所有浏览器的支持


您是否尝试过“数据:图像/bmp;base64,Base64DataGoesher…?API是否返回base64编码数据?的可能重复项?。您提到了“内容类型:image/bmp”,那么API可能会返回一个图像二进制文件。在这种情况下,您可以直接在image src中设置API URL。如果不想公开URL,则需要将图像数据编码为Base64,并将src设置为数据URL data:image/bmp;base64,${file}@ajai Jothi是的,好主意,但这是返回此图像的/POST请求。这个API不是我的,我无法编辑:@VitaliSkripka听起来你的API不是返回Base64图像,而是返回实际的二进制图像。因此,您必须将其编码为Base64 file=btoadata,然后img.src=`data:image/bmp;base64,${file}`。删除数据=Base64.decodedata;是的,没有帮助
let { data } = yield call(axios, requestConfig1);
data = Base64.encode(data)

const img = new Image();
img.src = `data:image/bmp;base64,${data}`;
let { data } = yield call(axios, requestConfig1);
data = btoa(unescape(encodeURIComponent(data)));

const img = new Image();
img.src = `data:image/bmp;base64,${data}`;