Version - OpenMRS 2.0.5
Rest Services version-2.23
I am trying to upload an image to a complex observation.I created a concept with complex type and imagehandler.When I try to use online , the image is getting uploaded and I can also download the image with the uri present in the response.
When I try with REST api however it does not work.No error occurs , but no uri with value is getting generated.Could you let me know what is the correct payload that I should be passing .
Is the feature available for 2.0.5 ?.The below is the sample json I was trying with.
“value”: Base 64 encoded value of file as string
How do I pass the filename also?.I tried putting filename field in the obs json , but it was throwing an error.So it’s going in as RAW.
@sajankos What do you have on your log ?
No i haven’t seen a functionality of passing the file-name directly to the URL of the obs resource.
You can do the following.
the value parameter takes in a converted value of the file
InputStream in = getClass().getClassLoader().getResourceAsStream("customTestDataset.xml");
ByteArrayOutputStream out = new ByteArrayOutputStream();
String value = DatatypeConverter.printBase64Binary(out.toByteArray());
you’ll just attach the actual file to the request like the way PostMan can do it
But how will I post the json body along with a file in binary for a complex obs in postman?
you just post the usual json body , but leave out the
and just upload the file via the “choose files” button , and the file will be attached to your request
I am not sure whether I am doing something wrong but there doesn’t seem to be an option to send json body in binary in postman.I can attach a file but not sent a body.A screen shot with json body would help with binary.
@dkayiwa, what the easiest way to send both the json body and also attach a file for complex obs ??
yes i went through that test , but am trying to figure out how to post that file in PostMan with the Json Body.
it seems post man cant post both the json body and the file at ago
Did you see this in my response? "complex obs file and name encoded as a multipart/form-data, with obs metadata included in a request parameter named ‘json’ "
Tried this also.called http://ipaddress/openmrs/ws/rest/v1/obs in postman.Getting the below error as attached in screenshot
Just For Future reference
i was trying to do the same thing , and i was succesfull after several trials ,
Ensure you run on the apropriate Version of Rest module , that contains the change set @dkayiwa posted above.
NB , Also make sure in your request header , you dont set
Content-Type , PostMan will automatically set it for , other wise You’ll run into oanother error solved here
see Screenhot from my PostMAN