Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

How do I create/modify multiple nodes in the JCR with a single sling servlet post form?

Avatar

Level 1

What I'm trying to do is migrate assets into a CQ instance from a WordPress website using an automation suite, Kapow Katalyst, that handles all the grunt work of filling out individual sling post action forms for each content item. Originally I was lead to believe that simply posting the file to the monitored node specified in workflows (/content/dam(.*/)renditions/original) would be enough to make CQ handle the rest of the work of populating the metadata. The form below is used by Kapow for each individual asset and has FILE_NAME replaced with the name of the resource stored in a MySQL database, then the automation browser submits the form, receives a status 200, and continues on to the next asset in the database.

<html> <body> <form method="POST" action="http://localhost:4502/content/dam/MigrationProject/FILE_NAME/jcr:content/renditions" enctype="multipart/form-data"> <input type="file" name="original" /> <input type="hidden" name="original" value="nt:file" /> <input type="submit"  /> </form> </body> </html>

The problem I'm having, however, is that the DAM is just seeing all of these newly created nodes as jcr:primaryType of sling:OrderedFolder and the workflows that try to run on these newly created nodes can be seen aborting in the console. When I recreated the same node structure as a sample DAM asset, using CRXDE, and then copied the uploaded node original to its proper place on my properly structured dam:Asset, CQ recognized it and immediately populated metadata. The structure I'm trying to create looks like this:

  • somefile.jpg       jcr:primaryType = dam:Asset
    •     jcr:content        jcr:primaryType = dam:AssetContent
      • renditions          jcr:primaryType = nt:folder
        • original        jcr:primaryType = nt:file       
          •     jcr:content           jcr:primaryType = nt:resource

Is it possible to do this inside of a single sling post form?

1 Accepted Solution

Avatar

Correct answer by
Level 10

You don;t need to adjust any thing just change to right url & parameters. Example curl command is [1] so form should be something like [2].

[1]   curl -v -u admin:admin --form file=@actualfilename.pdf --form fileName=actualfilename.pdf http://localhost:4502/content/dam/geometrixx/documents.createasset.html

[2]

<form method="POST" action="http://localhost:4502/content/dam/MigrationProject.createasset.html" enctype="multipart/form-data">
<input type="file" name="actualfilename.ext" />
<input type="hidden" name="fileName" value="actualfilename.ext" />
<input type="submit" />
</form>

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

You don;t need to adjust any thing just change to right url & parameters. Example curl command is [1] so form should be something like [2].

[1]   curl -v -u admin:admin --form file=@actualfilename.pdf --form fileName=actualfilename.pdf http://localhost:4502/content/dam/geometrixx/documents.createasset.html

[2]

<form method="POST" action="http://localhost:4502/content/dam/MigrationProject.createasset.html" enctype="multipart/form-data">
<input type="file" name="actualfilename.ext" />
<input type="hidden" name="fileName" value="actualfilename.ext" />
<input type="submit" />
</form>

Avatar

Level 1

Well I got the DAM to recognize my assets - but only when I create the structure of a dam:Asset manually and upload the file to /content/dam/MigrationProject/filename.jpg/jcr:content/renditions/original. It looks like the problem that I was having was that I had made the renditions folder a sibling of the jcr:content node (it should be a child) and as such this was confusing the DAM greatly. Thanks for the quick replies though.

Avatar

Level 1

For [1] : the software I'm using, I'm not sure if it supports curl commands (or at least I haven't figured out how to do it yet), so [2] is looking like a viable option. The only thing is, I tried this approach right off the bat and when the form is submitted the page returns with a status: 400 - Bad Request. So this was the reason that I went about trying to create the same node structure as a dam:Asset. Last night I made some changes to my robot so that it would automatically create the parent nodes of the destination folder with the proper primaryTypes and after I did, the assets appeared properly in the DAM (all images stored under content/dam/MigrationFolder even though they exist at a deeper level) but all of the thumbnails next to the filenames all display a loading "In-Progress" icon. It allows me to click on the image and brings up the metadata screen but no metadata is populated. Also, when I try to click the link to download the file, the page responds with a 404. In the workflow console, there are workflows started for each image that was uploaded, but they either are aborted or just remain in the console and report status STALE after awhile. Do you think it could be an issue with how I'm uploading the file? (I'm uploading from local filesystem)

Avatar

Level 10
See this Sling Post Servlet, see http://dev.day.com/docs/en/cq/current/developing/sling_cheatsheet.html. It does not really suit your needs. What I would recommend is to create a custom sling servlet and modify nodes in the sling servlet.

Avatar

Level 10
You use the JCR API in a custom sling servlet to modify the AEM JCR.