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.
Solved! Go to Solution.
Views
Replies
Total Likes
The outside Java app should only post to an AEM servlet.
So you need 2 parts:
1 - outside client app (which you have) that posts files to AEM.
2 - an AEM Sling servlet that uses the AssetManager API
See this article that does this exact use case from a outside Java Swing client:
https://helpx.adobe.com/experience-manager/using/multiple-digital-assets.html
Use of the AssetManager API is the best way when you want to upload files from an outside client.
Views
Replies
Total Likes
When coding the Servlet that accepts the file - use the AssetManager API. See this article --
https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html
Hope this helps...
Views
Replies
Total Likes
This will help only when my servlet inside OSGI container. But mine is standalone application. I am using it outside the AEM server. In the above link we are getting ResourceResolver from ResourceResolverFactory. In my case it will give null for ResourceResolver.
For your info If I have tried this using curl command
curl -u admin:admin -T D:\images\test.jpg http://localhost:4502/content/dam/test/test.jpg
It is working fine. I am getting metadata. But mine is java application.
Views
Replies
Total Likes
The outside Java app should only post to an AEM servlet.
So you need 2 parts:
1 - outside client app (which you have) that posts files to AEM.
2 - an AEM Sling servlet that uses the AssetManager API
See this article that does this exact use case from a outside Java Swing client:
https://helpx.adobe.com/experience-manager/using/multiple-digital-assets.html
Use of the AssetManager API is the best way when you want to upload files from an outside client.
Views
Replies
Total Likes
We have a video on our youtube channel that shows this use case: https://www.youtube.com/watch?v=smrFuVLfiBc
Views
Replies
Total Likes
Thanks smacdonald. It is working as expected.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies