首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法在spring boot中上传文件

无法在spring boot中上传文件
EN

Stack Overflow用户
提问于 2017-05-11 09:32:23
回答 2查看 1.5K关注 0票数 2

在过去的3天里,我一直在努力解决这个问题,当我尝试在我的spring boot项目中上传一个文件时,我一直收到以下异常。org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present

我不确定这是否会有所不同,但我将应用程序作为war部署到weblogic上,这是我的控制器

@PostMapping
public AttachmentDto createAttachment(@RequestParam(value = "file") MultipartFile file) {
    logger.info("createAttachment - {}", file.getOriginalFilename());
    AttachmentDto attachmentDto = null;
    try {
        attachmentDto = attachmentService.createAttachment(new AttachmentDto(file, 1088708753L));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return attachmentDto;
}

我可以在spring boot执行器中看到的多部件bean

在chrome中看到的有效负载

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-11 13:02:19

@RequestParm 'file‘需要Name属性

<input type="file" class="file" name="file"/>
票数 3
EN

Stack Overflow用户

发布于 2019-05-28 02:11:50

上面的解决方案对我来说都不起作用,但当我深入研究时,我发现spring security是罪魁祸首。即使我发送了CSRF令牌,我也反复遇到POST不支持的问题。当我在google chrome中使用开发人员工具进行检查,并在网络选项卡中看到状态代码时,我才知道我收到了禁止的403。我在Spring Security配置中添加了到ignoredCsrfMapping的映射,然后它完全可以正常工作,没有任何其他缺陷。我不知道为什么安全部门不允许我发布多部分数据。需要在application.properties文件中说明的一些强制设置如下:

spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB
spring.http.multipart.enabled=true
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43905066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档