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.