The Request Was Rejected Because No Multipart Boundary Was Found in Springboot

the request was rejected because no multipart boundary was found java

The problem is that I am setting the Content-Type by myself, let it be blank. Google Chrome will do it for me. The multipart Content-Type needs to know the file boundary, and when you remove the Content-Type, Postman will do it automagically for you.

Spring boot: The request was rejected because no multipart boundary was found in spring boot with ajax call?

The Issue is resolved with the following ajax code

 var itemData=new FormData($("#courseForm")[0]);
$.ajax({
type : "POST",
url : "/course/save",
data : itemData,
dataType : "json"
processData : false,
cache : false,
contenttype : false;
success : function(result) {
if(result.message !=null){
alert(result.message);
}
},
error : function(e){
alert("Error! Please enter proper data");
}
});
return false;

And we need to fetch the data in controller using @RequestParam annotation and the file using @RequestPart annotation

no multipart boundary was found

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

JAVA - SPRING - the request was rejected because no multipart boundary was found

I solved my problem getting Bytes from Multipart file, then convert to base64Encoded, and sending like String parameter to Service, and then convert base64Encoded to Bytes and then to File.

WEB

@Override
public String getUploadedFile(MultipartFile file, Integer fuenteId, Integer procesoId) {

try {
byte[] fileBytes = file.getBytes();
String base64Encoded = DatatypeConverter.printBase64Binary(fileBytes);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("file", base64Encoded);
map.add("procesoId", procesoId.toString());
map.add("fuenteId", fuenteId.toString());
HttpEntity<MultiValueMap<String, String>> requestEntity
= new HttpEntity<MultiValueMap<String, String>>(map, headers);
getRestTemplate().postForObject(url + "/uploadFile", requestEntity, String.class);
} catch (IOException ex) {
Logger.getLogger(UtilitarioServicioProxyImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return "";
}

SERVICE

@RequestMapping(path = "/uploadFile", method = RequestMethod.POST,
consumes = "application/*")
public String getUploadedFile(@RequestParam("file") String file,
@RequestParam("procesoId") Integer procesoId, @RequestParam("fuenteId") Integer fuenteId) throws IOException {

byte[] fileDecoded = DatatypeConverter.parseBase64Binary(file);
utilitarioServicio.getUploadedFile(fileDecoded, fuenteId, procesoId);

return "";
}

The request was rejected because no multipart boundary was found angular+spring

Try this ,

 const formData = new FormData();
formData.append("file", file);
formData.append("reportProgress", true);

use httpclient,

 return this.httpclient.post(this.urlUpload, formData);

FileUploadException: the request was rejected because no multipart boundary was found

As the exception says your request is missing some information: Boundaries.
a multipart/form-data should be like this:

POST /upload HTTP/1.1
Host: myhost
User-Agent: uploader/1.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Content-Type: multipart/form-data; boundary=----------287032381131322
Content-Length: {sizeofcontent}

------------287032381131322
Content-Disposition: form-data; name="file"; filename="myfile.txt"
Content-Type: text/plain

My file content;
------------287032381131322--

See the boundary parameter in the content-type is used as a delimiter for each data (it can be any string).
Notice extra "--" at the end to notify data end. You need to write these to successfully upload a file.



Related Topics



Leave a reply



Submit