I have a file ABC(inputstream) that needs to upload from Android App over Jersey Java Rest Server.I am able to send the file alone but I have jsonObj(object converted to json ) along with file.
I am trying to convert inputstream into json String and then insert it into jsonObj. But no luck. Please guide me the way to approach this.
Update [1]
Java Client:
with JSONObject
ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); JSONObject json = new JSONObject(); json.put("id", "1213"); json.put("name", "3"); json.put("date", "2013-12-09"); String input = new String( json.toString()); ClientResponse response = service.path("/insert/").type(MediaType.APPLICATION_JSON). post(ClientResponse.class,input);
with inputStream
String fileName="D://workspaces/src/readMe.pdf"; InputStream fileInStream = new FileInputStream(fileName); ClientResponse response = service.path("/uploadFile").type(MediaType.APPLICATION_OCTET_STREAM) .post(ClientResponse.class, fileInStream);
I hope Server code not required.
Now this work perfectly, But i want them together, i guess input stream can be merged with JSONObject, the question is how ?? some folks says that Jackson, but i need this client code on android application where i can not afford extra libs.