2 Replies Latest reply on Feb 25, 2015 6:22 AM by dberning

    REST API update an Image.

    dberning

      Can someone show me an actual example that works for the rest API Create Temporary Image?

       

      All I get is a 406 returned.

       

      Untitled.png

        • Re: REST API update an Image.
          samarth.shekhar02

          Hi don berning,

          Adding a code snippet which i hope will help.

           

            DefaultHttpClient httpClient = new DefaultHttpClient();

            HttpPost postRequest = null;

           

            HttpResponse response = null;

            Header[] headers = null;

            String url="http://localhost:8080/api/core/v3/images";

           

            try {

            MultipartEntity multiPartEntity = new MultipartEntity () ;

            FileBody fileBody = new FileBody("Image location") ;

            multiPartEntity.addPart("attachment",fileBody);

           

            postRequest = new HttpPost(url);

            postRequest.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials( username, password), "US-ASCII", false));

            postRequest.setEntity(multiPartEntity);

            headers = postRequest.getAllHeaders();

           

            response = httpClient.execute(postRequest);

           

          // Location value in header will give you the temporary url

            headers = response.getHeaders("Location");

            for (Header header : headers) {

            System.out.println(header.getValue());

           

            }

            }catch (ClientProtocolException e) {

           

            }

           

          Thanks,

          Samarth Shekhar