相关疑难解决方法(0)

获取HTTP状态400 - 必需的MultipartFile参数'file'在spring中不存在

我正在尝试使用上传文件spring.下面是我的代码我是如何工作的,但如果我尝试使用它,我得到这个response:

HTTP状态400 - 不存在所需的MultipartFile参数"file"

我不知道错误是什么.

我正在使用高级休息客户端进行测试,我将文件作为附件上传.

我的Javacode:

@RequestMapping(value = "/upload",headers = "Content-Type=multipart/form-data", method = RequestMethod.POST)
    @ResponseBody
    public String upload(@RequestParam("file") MultipartFile file)
    {
        String name= "test.xlsx";
        if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();
                BufferedOutputStream stream =
                        new BufferedOutputStream(new FileOutputStream(new File(name)));
                stream.write(bytes);
                stream.close();
                return "You successfully uploaded " + name + "!";
            } catch (Exception e) {
                return "You failed to upload " + name + " => " + e.getMessage();
            }
        } else {
            return …
Run Code Online (Sandbox Code Playgroud)

java spring file-upload

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

file-upload ×1

java ×1

spring ×1