[Solved] FileUploadException: the request was rejected because no multipart boundary was found

summary

Recently, in order to do a video detection, when using postman to upload a video, the code threw an error:

ERROR 13557 [] [http-nio-5000-exec-8] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found] with root cause

org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
        at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:178)

Background

File upload controller of business application layer:

@Resource
private FileService fileService;

@PostMapping(value = "video")
@ApiOperation(value = "Submit video recognition", httpMethod = "POST")
public Result video(@RequestParam("file") MultipartFile file, @LoginUser SysUser user, HttpServletRequest request) {
	Result<FileInfo> fileInfoResult = fileService.fileUpload(ArmConstant.BUCKET, file);
}

The file service in the above code is an interface defined based on feignclient

@FeignClient(name = ServiceNameConstants.FILE_SERVICE, fallbackFactory = FileServiceFallbackFactory.class, decode404 = true)
public interface FileService {
	@PostMapping(value = "/upload/{bucket}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	Result<FileInfo> fileUpload(@PathVariable("bucket") String bucket, @RequestParam("file") MultipartFile file);
}

The file service needs a supporting service, namely file center service, whose controller is defined as follows:

@RestController
@Slf4j
public class FileController {
	@PostMapping("/upload/{bucket}")
	public Result<FileInfo> fileUpload(@PathVariable("bucket") String bucket, @RequestParam("file") MultipartFile file) {
	}
}

analysis

Baidu and Google search all talked about how to set up postman, which once made me question the problem of postman, or my use of postman. Online search, we must take their own critical thinking analysis, many articles are blindly copied. Moreover, as a mature automatic interface testing tool, postman will hardly be found by you and me.

But I’m familiar with the use of postman. In fact, there is no problem with postman configuration:

shelve for one night.

It’s really impossible. Global search multipartfile :

suddenly find something. What’s the difference between @requestpart and @requestparam

Replace @requestparam in three places with @requestpart to solve the problem;

I have to say that feign has a lot of holes. However, we can’t find any information about fileuploadexception: the request was rejected because no multipart boundary was found in feign GitHub.

Feign’s pit, refer to my another blog fallback factory

Extension

What is the difference between @requestpart and @requestparam
write another article about the difference between @requestparam and @requestpart and feign’s comments


Read More: