Link to home
Create AccountLog in
Avatar of mozboones

asked on

Javax Client.WebTarget: Issue creating The Request Body to support the content-type of multipart/form-data

Trying to write a ClientBuilder based method (Java/selenium tool) that handles the following condition: The Request Body for this api should be of type multipart/form-data and it should have a boundary differentiated between file attached to form and form fields

I have done the mutli Part Content in c# but the group needs to be written in Java. Here's the c# code that works for creating the request body. I just having some mental blocks writting the Java HTTP Client version (could not find any realistic samples out there)

Note: I trying to upload an application/msi or application/ms-dos-exec file via the form. Here's my c# code
		 MultipartFormDataContent multiPartContent = new
		 MultipartFormDataContent("----WebKitFormBoundaryliUiaMuaEcUBLr3A"); ByteArrayContent byteArrayContent = new
		 ByteArrayContent(LogoRequest.Content); byteArrayContent.Headers.Add("Content-Type", "image/png"); String
		 FileName = LogoRequest.Name; String ContentDispositionStr = "form-data; name=" + "\"logoImageFile\"" +"; " +
		 "filename=" + FileName; byteArrayContent.Headers.Add("Content-Disposition", ContentDispositionStr);
		 multiPartContent.Add(byteArrayContent); requestMessage.Content = multiPartContent;

Open in new window

Avatar of CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not sure what the question is. Are you saying you want us to translate that code into Java?
Avatar of mozboones

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
OK, so if the question is no longer applicable, please accept your last comment to close the question
Avatar of mozboones


I did not get a chance to receive a solution. There was an issue with how the solution page that prevented me from responding to the question from the Expert.

I investigating on my end to see if this a setting issue.