Add a attachment to CouchDB with play framework JavaAPI

I tired to write a rest API which act as a mediator between clients and CouchDB API. This was done using Playframework's Java API. I wrote the following controller method which takes a POST request which contains file name, content-type and file to be stored as parameters and send as a PUT request to CouchDB.

   public static Result putAttachment(){
        Http.MultipartFormData body = request().body().asMultipartFormData();
        Http.MultipartFormData.FilePart picture = body.getFile("picture");
        String fileName=null;
        String contentType=null;
        File file=null;
        if (picture != null) {
            fileName = picture.getFilename();
            contentType = picture.getContentType();
            file = picture.getFile();
        } else {
            //TODO implement
        String restServiceUrl = ""+fileName;
        F.Promise<play.libs.WS.Response> future =play.libs.WS.url(restServiceUrl)
        return Results.ok(future.get(50000000).getBody());


Popular posts from this blog

Create new Java Class files at runtime

Creating a Pentaho BI server cluster

Using iReport plugin for Jasper Reports in Netbeans