3 Replies Latest reply on Jan 26, 2013 5:54 PM by lancedolan

    How to acquire instance of AssetStore or AssetHandler?

    lancedolan

      How do I acquire an instance of AsseStore or AssetHandler? My end goal is to use them to create a new rendition, for example:

       

      Resource imageResource = resourceResolver.getResource(pathInDam);

      Asset asset = imageResource.adaptTo(Asset.class);

      AssetHandler handler = AssetStore.getAssetHandler(asset.getMimeType());

      ThumbnailConfig myConfig = new ThumbnailConfig(){

          public boolean doCenter() {return true;}

          public int getHeight() {return 95;}

          public int getWidth() {return 95;}

      };

      List<ThumbnailConfig> configs = new ArrayList<ThumbnailConfig>();

      configs.add(myConfig);

      handler.createThumbnails(asset, configs);

       

      The missing piece to the puzzle is on the 3rd line: AssetStore.getAssetHandler is not a static method and I've just spent 2 hours decompiling half the jars in sling trying to figure out how the WorkFlowProcess class gets its instance to the class so that I can do the same.... I'm hoping there's either a factory I'm not familiar with or else a registered service I just can't find.

       

      Cheers and thanks

       

      -Lance Dolan

      CITYTECH Inc

        • 1. Re: How to acquire instance of AssetStore or AssetHandler?
          lancedolan Level 1

          Ah, I found that it is in fact registered as a service... should have checked this first.

           

          solution:

           

          SlingBindings bindings = (SlingBindings) req.getSlingRequest().getAttribute(SlingBindings.class.getName());

          SlingScriptHelper slingScriptHelper = bindings.getSling();

          AssetStore store = slingScriptHelper.getService(AssetStore.class);

           

          My next hurdle is figuring out why the rendition isn't persisted into CRX after the method successfully runs:
          handler.createThumbnails(asset, configs);

           

          If I log.debug() all renditions after running this, I see that the rendition is added to the Asset's renditions list, with the correct path and name, but the rendition doesn't exist in CRX afterwards. Hmm.

          • 2. Re: How to acquire instance of AssetStore or AssetHandler?
            JS Bournival

            Hi Lance,

             

            Have you been successful on this issue.  I'm having the same problem:  my asset seem to have the newly created renditions, I can even get a link to it.  But, as you might guess, the link throws a 404 since the rendition isn't in the CRX repo.

             

            I would be glad to read what you have done to make it work.

             

            Thank you.

            • 3. Re: How to acquire instance of AssetStore or AssetHandler?
              lancedolan Level 1

              It's been 6 months, so I don't recall much except that I solved it shortly after posting the comment. Probably grabbed an underlying Session instance and called the save() method?