Expand my Community achievements bar.

SOLVED

save image in dam mediate a sling to then call it mediate another servlet

Avatar

Level 2

hi friends again here, I am now creating a node where I also want to save an image selected by the user in the dam to reuse but I have no idea how to perform this process due to the little knowledge I still have from the sling thanks for the collaboration and I appreciate very much all the help you can give me.

Here My Code

package com.globant.aem.gamer.store.core.servlets;

import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.servlet.ServletException;
import java.io.IOException;

@SlingServlet(paths = {"/bin/gamer-store/tools/addGame"}, methods = {"GET"})

public class addGame extends SlingSafeMethodsServlet {

   @Reference
   ResourceResolverFactory resourceResolverFactory;
   ResourceResolver resourceResolver;

   @Override
   protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

   throws ServletException, IOException {

   try {

  String category = request.getParameter("formCategory");
   String name = request.getParameter("formName");
   String price = request.getParameter("formPrice");
   String publishDate = request.getParameter("formPublishDate");
   String description = request.getParameter("formDescription");
   resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
   Resource resource = resourceResolver.getResource("/content/gamerstore/games/" + category);
   Session session = resourceResolver.adaptTo(Session.class);
   Node nodeFather = resource.adaptTo(Node.class);

  try {

  Node nodeGame = nodeFather.addNode(name);
   nodeGame.setProperty("category", category);
   nodeGame.setProperty("name", name);
   nodeGame.setProperty("price", price);
   nodeGame.setProperty("publishDate", publishDate);
   nodeGame.setProperty("description", description);

   session.save();

   } catch (Exception ex) {

  }

  } catch(Exception ex){

  }

  }

}

The idea is to have an image field and I do not know what should be kept in that field if the route of the dam to know that this image belongs to that node I appreciate the help that clarifies this doubt since I am not clear on how to do it already that after this the idea is to call the image to appear in a form

1621835_pastedImage_0.png

to then call the image and appear in each box of the image thank you for the help you can give me and I hope you have made me understand

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

Check Upload images from desktop to DAM using Image Component  if helps.

You can check and upload images if image is not exists from form and can refer directly in your display page or save as property.

I did not understand the image part from you requirement, If image are already exist why don't you use that or default one or allowed browse option in a form to browse existing image from Dam in form and display that image.



Arun Patidar

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi,

Check Upload images from desktop to DAM using Image Component  if helps.

You can check and upload images if image is not exists from form and can refer directly in your display page or save as property.

I did not understand the image part from you requirement, If image are already exist why don't you use that or default one or allowed browse option in a form to browse existing image from Dam in form and display that image.



Arun Patidar

Avatar

Level 2

Not the image to a do not exist in the Dam the idea is that with a form of registration of games which only need to enter the field of the image, when it is to gurdar my store the new game and the reference image in the dam for then reuse it in another form, I hope if you have asked me to fill a few in the request, I thank you for your previous reply, it is helping me a lot.

Avatar

Level 10

You are trying to save image in DAM. You should be using AssetManager API (not Node API) as discussed here:

  https://helpx.adobe.com/experience-manager/using/upload_experience_manager_dam.html