3

Using Rest Client Chrome tool, I am uploading a JSON file say sample.json in my request. Getting below exception. Tried Passing header as multipart/form-data and also no passing the latter. But the result is same. Am I doing right?

the request 
was rejected because no multipart boundary was found

..

public HttpEntity<?> uploadJsonFile(@PathVariable("jsonFileID") String
    jsonFileID, @RequestParam("file") MultipartFile file) throws Exception 
    {
        // Some code here
    }

..

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.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:831) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
at org.apache.catalina.connector.Request.parseParts(Request.java:2884) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
at org.apache.catalina.connector.Request.parseParameters(Request.java:3232) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
i2ijeya
  • 15,952
  • 18
  • 63
  • 72

3 Answers3

3

It looks like you're not specifying a boundary in your HTTP request header - see here for what I mean Unable to send a multipart/mixed request to spring MVC based REST service

Content-Type: multipart/mixed;boundary=YourBoundaryOfChoiceHere
xenocratus
  • 116
  • 4
  • 2
    What is that boundary mean? – i2ijeya Mar 01 '19 at 18:13
  • 2
    Content-Type: multipart means essentially just that - a message split into multiple parts and sent as such. The boundary is a separator between those parts. if your boundary was "abc", the separator would be "--abc--" as defined in HTTP standards – xenocratus Mar 01 '19 at 21:26
3

For your eyes only, in java you might use :

String boundary = Long.toHexString(System.currentTimeMillis());
            request.getHeaders().setContentType("multipart/form-data; boundary="+boundary);
-1

Remove 'Content-Type': 'multipart/form-data' from header

Worked for me