SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

RestHeart Post file java example #119

Closed dumanps closed 8 years ago

dumanps commented 8 years ago

Sorry, how can i send post request with using java http request? I want insert any value in my collection.have any example for this?

I'm trying do it with jersy lib like this:

Client jersyClient = getJersyClient(); WebTarget target = jersyClient.target("http://10.146.136.40/simpleFilesMongoDbTest/photo.files") FormDataBodyPart fileFormDataBodyPart = new FormDataBodyPart("file", Files.readAllBytes(path), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataBodyPart fileNameFormDataBodyPart = new FormDataBodyPart("filename", path.getFileName().toString(), MediaType.APPLICATION_JSON_TYPE);

Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));

and answer is 406 "http status code" : 406 , "http status description" : "Not Acceptable" , "message" : "This request does not contain any binary file"

But I have a byte[] - Files.readAllBytes(path)

ujibang commented 8 years ago

have a look at integration test classes. they use apache http client library

for example see PostCollectionIT.java or for files GetFileHandlerIT.java

dumanps commented 8 years ago

Thank you, I'll try to use Apache lib