Am trying to upload an image file in the request body with the following script through a JSR223 Sampler. The below script is failing due to my application doesn't support multipart entinty. Is there any way I solve this?
import org.apache.http.HttpHeaders
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
import org.apache.http.entity.mime.HttpMultipartMode
import org.apache.http.entity.mime.MultipartEntityBuilder
import org.apache.http.impl.client.HttpClients
def imageFileName = "C:\\Users\\IMAGES\\IMG00001.dcm"
def urlRequest = 'https://' + ${BASE_URL_1} + '/api/v3/storage/namespace/7c762733-009f-4527-81ea-571d1cf6e9d2/image?sid=' + vars.get('SIDVALUE') + '&study_uid=1.2.300.0.7230010.3.1.2.2595064201.8112.1216202112026121&image_uid=1.2.840.113704.7.1.0.1356918323635126.1521373008.110'
def postRequest = new HttpPost(urlRequest);
def file = new File(imageFileName);
def builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, imageFileName);
def entity = builder.build();
postRequest.setEntity(entity);
def header = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/dicom");
def headers = Arrays.asList(header)
def client = HttpClients.custom().setDefaultHeaders(headers).build()
def response = client.execute(postRequest);