Master
Master

Reputation: 2959

HTTP PUT request to save data to CouchDB Server - Java Android?

I want to save a document in CouchDB server for that I am writing my own PUT request. I can do so using curl command:

> curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/artwork.jpg?rev=2-2739352689 --data-binary @artwork.jpg -H "Content-Type: image/jpg"

How can I write the same in PUT Request form in Java like:

HttpPut request = new HttpPut(url);
            StringEntity stringEntity = null;
            try {
                stringEntity = new StringEntity(
                        (new JSONObject(map)).toString());
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            stringEntity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
                    "application/json"));
            request.setHeader("Content-type", "application/json");
            request.setEntity(stringEntity);

Any idea, how to write such a put request as written in Curl command given above.

Upvotes: 0

Views: 1102

Answers (1)

rycho
rycho

Reputation: 89

You need to deal with binary data, I was just doing this today and answered another post: Couchdb Upload Image via Httpclient

Upvotes: 1

Related Questions