相关疑难解决方法(0)

邮差:所需的请求部分'文件'不存在

我想通过邮递员将图像上传到我的Rest API.我正在使用spring boot框架.这是屏幕截图:

在此输入图像描述

我也没有像我在其他堆栈溢出答案中找到的那样设置任何头文件,因为它给出了多部分边界错误.

现在,下面是我的控制器代码:

package com.practice.rest.assignment1.controller;

import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.practice.rest.assignment1.model.Product;
import com.practice.rest.assignment1.service.CatalogueService;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

@RestController
@RequestMapping("/CatalogueController/")
public class CatalogueController{

    @Autowired
    private CatalogueService catalogueService;

    @RequestMapping(value = "addProduct", method = RequestMethod.POST , consumes = "multipart/form-data")
    public Product addProduct(@RequestParam String productJson, @RequestParam MultipartFile file) throws JsonParseException, JsonMappingException, IOException {


        Product product = new ObjectMapper().readValue(productJson, Product.class);
        byte[] …
Run Code Online (Sandbox Code Playgroud)

rest multipartform-data spring-mvc spring-boot postman

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