Logo

Logo

请求出现“Content type ‘application/octet-stream‘not supported“错误

Pastore Antonio
Pastore Antonio 2023年11月01日
1017 阅读 0 评论 约 1443 字 阅读约 3 分钟

请求出现”Content type ‘application/octet-stream‘not supported“错误

  • 错误描述:
    Content type ‘application/octet-stream‘not supported,即内容类型’application/octet-stream ‘不支持。由此可见,我们这里传的参数需要’application/octet-stream’类型支持。
    octet-stream:任意二进制流数据。
    application/octet-stream:只能提交二进制或文件。
  • 出现错误的请求:
    POST 请求,需要传一个 file 文件和一个 json 字符串,如下图所示:
    在这里插入图片描述
    react 前端提交表单传参这样写,此时 blackListBatch 传的是 json 字符串,如下:
const { file } = values;
const formData = new FormData();
formData.append('file', file[0].originFileObj);

const newValue = _.cloneDeep(values);
delete newValue.file;
const json = JSON.stringify(newValue);
formData.append('blackListBatch', json);

const params = {
  data: formData,
  callback: () => {
    message.success(intl('导入成功'));
  },
};
// 请求接口
offlineImport(params);

然后浏览器就出现了上面的报错。

  • 解决办法:
    由错误描述可知,我们这里不能传一个json字符串,而是一个二进制,这时需要使用 Blob() 构造函数将 json 字符串转化为 Blob 对象(Blob 对象表示一个不可变、原始数据的类文件对象,它的数据可以按文本或二进制的格式进行读取)放到 formData 中,如下:
const { file } = values;
const formData = new FormData();
formData.append('file', file[0].originFileObj);

const newValue = _.cloneDeep(values);
delete newValue.file;
const json = JSON.stringify(newValue);
// 将 json 字符串转化为 Blob 对象
const blob = new Blob([json], {
 	type: 'application/json',
});
formData.append('blackListBatch', blob);

const params = {
  data: formData,
  callback: () => {
    message.success(intl('导入成功'));
  },
};
// 请求接口
offlineImport(params);

type: ‘application/json’ 表示将会被放入到 blob 中的数组内容的类型是 json 字符串。

如上,便可解决该报错。

查看完整代码

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它

附件下载

共 1 个文件
在这里插入图片描述
PNG 19.1 KB
部分文章可能存在转载,如果涉及到侵权,请联系删除文章。

探索AIGC相关的精彩内容,共 15 篇文章

Azure AI 服务之语音识别

简介 Azure AI 服务中的语音识别 API 是微软提供的一项先进技术,旨在帮助开发者轻松实现语 ... 请求出现“Content type ‘application/octet-stream‘not supported“错误

2026-02-17 · Xzavier Aaron
MCP | 一文详解什么是 MCP以及 MCP 可以做什么

一、什么是 MCP MCP(Model Context Protocol)是一个专为大型语言模型(L ... 请求出现“Content type ‘application/octet-stream‘not supported“错误

2026-02-14 · Shen, Luke
你的工作流程,值得一个“全自动数字分身”:录制、截图、成文,一气呵成

一、一句话认识 TestFlow Recorder 在数字化工作环境中,如何准确记录操作步骤并生成清 ... 请求出现“Content type ‘application/octet-stream‘not supported“错误

2026-02-14 · Xzavier Aaron
Flowise 前端框架配置指南

用户需求 问题:有没有适合配置 Flowise 的前端框架? 目标:寻找类似 Open WebUI ... 请求出现“Content type ‘application/octet-stream‘not supported“错误

2026-02-14 · Xzavier Aaron