Upload GIF image into dam programmatically AEM | Community
Skip to main content
Level 2
August 7, 2018

Upload GIF image into dam programmatically AEM

  • August 7, 2018
  • 3 replies
  • 5485 views

Hi,

I'm trying to upload external gif image programmatically using com.day.cq.dam.api.AssetManager api but it is not working as expected. i'm able to upload external jpg and png images.

example : Fat Cat Success GIF - Find & Share on GIPHY

For above gif content type is html not gif  is that is the issue?.

Can anyone help me with this, please?

Thanks,

Santosh

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

arunpatidar
Community Advisor
Community Advisor
August 7, 2018

Hi,

For me below code is working for jpeg and gif.

aem63app-repo/UploadAssets.java at master · arunpatidar02/aem63app-repo · GitHub

I am succesfully able to upload gif and used in page as well.

for image you've share is video, not an gif. You can try Busy Chis Sweet Home GIF - Find & Share on GIPHY

Thanks
Arun

Arun Patidar
smacdonald2008
Level 10
August 7, 2018

Uploading Assets typically involve writing a Sling Servlet and use the AEM Asset Manager API. See this article - Adobe Experience Manager Help | Uploading files to Adobe Experience Manager DAM using AssetManager API

Jitendra_S_Toma
Level 10
August 7, 2018

Santhosh,

Can you tell us what is not working as per your expectation? Does post request not go through? Any error log you see in the response?

October 6, 2022

Hi please try this it worked for me


Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "aemuser");
ResourceResolver resolver = resolverFactory.getServiceResourceResolver(param);

String imageUrl = "https://lh4.googleusercontent.com/cjh5t_mnSYuW_RnVI922M9kjxW8leJGp8nCwWdBjOQxz_RzNkuvVIHaxzDrZ-neDiFt71jyRKAQ4_2DTiv6R_vlZX0uUBGxLWmDR6Wa2gqqPJhgF7UzfqwYQJLTnDH0fKPt7wUc";
URL url = new URL(imageUrl);
InputStream is = url.openStream();
AssetManager assetMgr = resolver.adaptTo(AssetManager.class);
String newFile = "/content/dam/folderpath/1gi_NJv844BNNRwBXzN5ccgOgnVPHqnh6.jpg";
assetMgr.createAsset(newFile, is, "image/jpeg", true);// mention  meme type for me it is jpeg