Hi Team,
I'm trying to create a DAM asset(image or zip file) which is uploaded through HTML file upload field but the asset is not getting created properly. I'm able to create uploaded image in file system(just to check whether input stream is correct or not) with the same input stream but not DAM asset. Please help.
HTML Multipart form
<form action="/bin/uploadDAMAsset" method="post" target="_blank" enctype="multipart/form-data">
<input type="file" id="inputFile" name="inputFile">
<input type="submit" value="Submit">
</form>
AEM Servlet code
Map<String, RequestParameter[]> requestParameterMap = request.getRequestParameterMap();
for(Entry<String, RequestParameter[]> paramPair : requestParameterMap.entrySet()) {
String key = paramPair.getKey();
if(key.equals("inputFile") ) {
RequestParameter[] values = paramPair.getValue();
RequestParameter paramVal = values[0];
try {
InputStream inputStream = paramVal.getInputStream();
ResourceResolver resourceResolver = request.getResourceResolver();
if(null != inputStream) {
AssetManager assetMgr = resourceResolver.adaptTo(AssetManager.class);
assetMgr.createAsset("/content/dam/test/emails/BB.jpg", inputStream, "image/jpeg", true);
}
} catch (IOException e) {
LOGGER.error("Error while getting the input stream and creating DAM asset: {} {}" , e.getMessage(), e);
}
}
}
Thanks in Advance!
AryA
Views
Replies
Total Likes
Hi @Dinu_Arya
Can you add the below code after assetMgr.createAsset() method:
resourceResolver.commit();
This will persist your changes.
You can see the adobe documentation here: https://www.adobe.io/experience-manager/reference-materials/6-5/javadoc/org/apache/sling/api/resourc...
Regards,
Arpit Varshney
Hi @ArpitVarshney ,
I tried this now but still no renditions and original rendition is empty.
Regards,
AryA
Hi @Dinu_Arya
Is the loggedin user has appropriate permission to create dam assets. Can you try using admin account and check?
Also, please check error logs and share if you see any error?
Regards,
Arpit Varshney
Hi,
Please check https://github.com/arunpatidar02/aem63app-repo/blob/master/java/UploadAssets.java if this helps. This example shows how to upload the assets from local but you can get idea to create asset in DAM once you have InputStream
I'm getting 404. Looks like blob folder is not there.
It was , in the url, corrected now.
Hi @Dinu_Arya
When you are trying to create an asset, the resource resolver should be something that service user with appropriate permissions on that node. check the below link to create the user.
Hope this helps!
Thanks,
Kiran Vedantam.
Hi @Kiran_Vedantam ,
Yes. Actually I'm getting the resourceResolver from servlet's request. As suggested, I used system/service user flow of getting resource resolver but it also didn't help.
The issue is resolved by using byte array input stream.
Thank you for your inputs - @arunpatidar @ArpitVarshney @Kiran_Vedantam
Hi @Dinu_Arya @arunpatidar ,
I have used the implementation for image file upload but in backend
Map<String, RequestParameter[]> requestParameterMap = request.getRequestParameterMap();
In requestParmeterMap i am not able to see key inputFile.
Any help
Views
Replies
Total Likes
Views
Likes
Replies