reportportal / service-api

Report portal. Main API Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

azarudeenanifa opened this issue · comments

Hi Team,

If i am trying to post log along with multiform attachment, I am getting following error. It is happening over code and postman as well.

{
"errorCode": 5000,
"message": "Unclassified error [Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found]"
}

Sample Java Code:

HttpPost` request = new HttpPost(url);
try (CloseableHttpClient client = HttpClients.createDefault()) {			
	request.addHeader("Authorization", getToken());
	request.addHeader("Content-Type", "multipart/form-data");

	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, file.getName())
			.addTextBody("json_request_part", mapper.writeValueAsString(obj),ContentType.DEFAULT_BINARY);
	request.setEntity(builder.build());

	return client.execute(request,
			httpResponse -> mapper.readValue(httpResponse.getEntity().getContent(), Map.class));
}

@azarudeenanifa As per RFC 2046, section 5.1.1.:

The Content-Type field for multipart entities requires one parameter, "boundary".

Doing so:

request.addHeader("Content-Type", "multipart/form-data");

You override client's Content-Type header with invalid one, without mandatory parameter "boundary". That's why you absolutely legitimately get this error: "the request was rejected because no multipart boundary was found".

For anyone who ever asked me and my colleagues how to send batch requests to Report Portal by own code I strongly recommend to get familiar with RFC 2046 - MIME types and RFC 7578 - Multipart requests. The latter one is rather strict and any nonconformity (E.G. LF instead of CRLF as by standard in a single place) will lead to whole request rejection with an obscure reason, absolutely legitimately.

Apart from that the question of compiling correct multipart request is nothing to do with Report Portal. I believe this is the last time I answering this question and I'm going to ignore or close without explanation any further such questions.