How to upload image in Dam using standalone application which will generate metadata?

Avatar

Avatar

vasim_akram_sha

Avatar

vasim_akram_sha

vasim_akram_sha

15-02-2017

Hi,

I have a image in local drive. I want to upload that image to in my AEM dam. For that I have written following code.

public class ThroughHttpPost { public static void main(String[] args) { // TODO Auto-generated method stub File file = new File("D:\\images\\test.jpg"); byte[] bytesArray = new byte[(int) file.length()]; FileInputStream fis; try { fis = new FileInputStream(file); fis.read(bytesArray); //read file into bytes[] fis.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DefaultHttpClient httpClient = new DefaultHttpClient();//Client HttpPost postRequest = new HttpPost("http://localhost:4502/content/dam/test");//Post Request to specified URL httpClient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin")); ByteArrayBody bab = new ByteArrayBody(bytesArray, "test.jpg"); MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create(); reqEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("test.jpg", bab); postRequest.setEntity(reqEntity.build()); try { HttpResponse response = httpClient.execute(postRequest); response.getStatusLine(); System.out.println("done"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

I am able to push that image to dam. But the problem is that it is taking the image as nt:file. It doesn't have any metadata as shown in attachment. 

View Entire Topic

Avatar

Avatar

vasim_akram_sha

Avatar

vasim_akram_sha

vasim_akram_sha

16-02-2017

Thanks smacdonald. It is working as expected.