无法在春季启动中上传文件 [英] Can't upload files in spring boot

查看:72
本文介绍了无法在春季启动中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去3天来我一直在为此苦苦挣扎,当我尝试在我的spring boot项目中上载文件时,我一直遇到以下异常. org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present

I've been struggling with this for the past 3 days now, I keep getting the following exception when I try upload a file in my spring boot project. org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present

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

I'm not sure if it makes a differance but I am deploying my application as a war onto weblogic, here is my controller

@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;
}

在弹簧启动执行器中可以看到的多部分豆子

multi part beans I can see in spring boot actuator

在Chrome浏览器中看到的有效载荷

payload seen in chrome

推荐答案

@RequestParm文件"需要名称属性

Name attribute is required for @RequestParm 'file'

<input type="file" class="file" name="file"/>

这篇关于无法在春季启动中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆