巨坑啊!异常FileUploadException: the request was rejected because no multipart boundary was found

admin模块中单controller

    @PostMapping(value="/apk/fileApk",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ResponseBody
    public R fileApk(@RequestParam("file") MultipartFile file) {
        R r = fileFeign.fileApk(file);
        if (!ScbUtils.toR(r)) {
            return r.error("文件上传失败");
        }
        return r.ok();
    }

admin中的Feign

    @FeignClient(value = "mediafileupload", fallback = FileFeignFallback.class)
    public interface FileFeign {
        /**
         * 上传图片
         *
         * @param file
         * @return
         */
        @ApiOperation("上传图片")
        @PostMapping(value = "/v1/file/fileImg",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
        public R fileImg(@RequestParam("file") MultipartFile file);

        /**
         * fileApk
         *
         * @param file
         * @return R
         */
        @ApiOperation("上传文件")
        @PostMapping(value = "/v1/file/fileApk",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
        public R fileApk(@RequestParam("file") MultipartFile file);
    }

fileupload模块中的Controller

    @ApiOperation("上传文件")
        @PostMapping(value = "/v1/file/fileApk",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
        public R fileApk(@RequestParam("file") MultipartFile file) throws Exception {
            R r = new R();
            String originalFilename = file.getOriginalFilename();
            //文件路径
            String url = fileService.fileApk(file);
            assert originalFilename != null;
            File toFile = new File(originalFilename);
            InputStream ins = file.getInputStream();
            inputStreamToFile(ins, toFile);
            ins.close();
            ApkFile apkParser = new ApkFile(toFile);
            ApkMeta apkMeta = apkParser.getApkMeta();
            //文件包名
            String packageName = apkMeta.getPackageName();
            DecimalFormat f = new DecimalFormat("#0.0");
            long length = toFile.length();
            double sizeLength = (double) length / 1024 / 1024;
            //文件大小
            String size = f.format(sizeLength);
            //md5
            String md5 = MD5Util.MD5(originalFilename);
            apkParser.close();
            Map<String, Object> map = new LinkedHashMap<>(4);
            map.put("apkUrl", url);
            map.put("packageName", packageName);
            map.put("size", size);
            map.put("apkMd5", md5);
            return r.ok(map);
        }

报错信息 (admin模块调用fileupload模块过程中报的错)

    org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
    	at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:831)
    	at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256)
    	at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280)
    	at org.apache.catalina.connector.Request.parseParts(Request.java:2868)
    	at org.apache.catalina.connector.Request.parseParameters(Request.java:3216)
    	at org.apache.catalina.connector.Request.getParameter(Request.java:1137)
    	at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
    	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:75)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:748)
FileUploadException: the request was rejected because no multipart boundary was found

写得很清楚,客户端的multipart编码不正确。

这个在哪改。。。大哥

你把

public R fileImg(@RequestParam("file") MultipartFile file);

换成

@RequestPart

试试看,我不熟悉Feign,没辙你就百度。

好吧 还是谢谢了

不要直接用postman工具来测试,要在html提交post请求