Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no multipart boundary was found

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]
like image 587
i2ijeya Avatar asked Oct 23 '25 12:10

i2ijeya


2 Answers

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
like image 140
xenocratus Avatar answered Oct 26 '25 04:10

xenocratus


For your eyes only, in java you might use :

String boundary = Long.toHexString(System.currentTimeMillis());
            request.getHeaders().setContentType("multipart/form-data; boundary="+boundary);
like image 21
Bastien Gallienne Avatar answered Oct 26 '25 04:10

Bastien Gallienne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!