org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream;charset=UTF-8' not supported
作者:
DPDK开发
栏目:
公开
2024-02-21 11:01
447
根据你提供的错误信息,看起来是后端Spring框架不支持接收
application/octet-stream
类型的内容。
如果你想在后端使用MultipartFile接收文件,可以尝试更改前端代码以发送multipart/form-data类型的请求。以下是一个示例:
const fs = require('fs');
const FormData = require('form-data');
const axios = require('axios');
// 创建FormData对象
const formData = new FormData();
formData.append('file', fs.createReadStream('path/to/file')); // 替换为实际的文件路径
// 发送POST请求
axios.post('/upload', formData, {
headers: formData.getHeaders()
.then(response => {
console.log(response.data);
.catch(error => {
console.error(error);
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
// 省略其他代码
@PostMapping("/upload")
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
// 处理上传逻辑
// ...
通过上述修改,在前端将文件作为multipart/form-data类型发送到后端,并且在后端使用@RequestParam注解来接收文件参数,应该能够解决Content type not supported的问题。
请确保导入了正确的依赖项(如form-data和axios),并根据实际情况调整路径和路由等信息。同时也需要注意在后端对上传文件进行适当验证和处理。
内容由零声教学AI助手提供,问题来源于学员提问
本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://sdn.0voice.com/?id=2744
这段文字描述了一种网络模块(可能是以太网模块)在与对等设备(peer)交互时的工作流程,主要涉及模式切换的过程。以下是每个步骤的详细解释:启动时设置对等设备能力:当系统启动时,客户端需要调用setPeerEthCapabilit...
这段文字描述了一些网络流量的类型及其处理路径。以下是对每一项的解释:VLAN-baseddownlinktraffic,tetheredtoappssoftwarepath:基于VLAN(虚拟局域网)的下行流量,依赖...
假设我们有一个名为 myapp-backend 的 Deployment,它运行在 Kubernetes 集群内部,并通过 ClusterIP 类型的 Service 暴露给内部其他服务使用。现在我们希望这个服务也可以被集群外部的客户端访问到,而不仅仅是内部服务。这时候就可以使用 ExternalName 类型的 Service,在 Kubernetes 中创建一个与 myapp-backend 同名的 Service,并将其类型设置为 ExternalName,同时指定一个外部 DNS ...
2023年05月12日
mDNS_SetupResourceRecord(&sr->RR_PTR, mDNSNULL, InterfaceID, kDNSType_PTR, kStandardTTL, kDNSRecordTypeShared, artype, ServiceCallback, sr);
为什么 RR_PTR还是PTR类型的呢
env_logger::init();
// We will reuse the same worker manager across all connections, this is more than enough for
// this use case
let worker_manager = Data::new(WorkerMa...
> [email protected] lint C:\Users\江军\Desktop\Vue学习\Vue3-big-event-admin
> eslint . --fix
Oops! Something went wrong! :(
ESLint: 9.14.0
A config object is using the "overrides" key, which is not supported in flat config syst...