2

I am trying to retrieve multimedia content from Tridion using DD4T with Java. Can anyone let me know how this can be done?

I am using below syntax to create generic component and then trying to retrieve the image from Tridion component:

GenericComponent comp = (GenericComponent) request.getAttribute(Constants.COMPONENT_KEY);
comp.getMultimedia().getURL();

Not sure how can I retrieve this image.

  • Can you give more detail as to what you're trying to achieve? Do you need just the metadata if the Multimefia? Or are you looking for the binary content? – Mihai Cădariu Jul 22 '14 at 6:58
  • I want the binary content – user1090 Jul 22 '14 at 7:14
  • If you have a URL, retrieving the binary has nothing to do with Tridion anymore. This may be helpful: stackoverflow.com/questions/3221979/… – Frank van Puffelen Jul 22 '14 at 13:53
  • I'm not familiar with DD4T's approach, but most DB-based systems will have a filter associated with the binaries, and intercept the URL call, retrieve the binary in question - possibly cache it in File System - then return the binary to the browser. Is DD4T correctly configured with the required filters? – Nuno Linhares Jul 22 '14 at 16:09
1

You can use LinkResolver which is available in org.dd4t.core.resolvers.LinkResolver. Also make sure that in your dd4t template you have set the depth of link to the level which you have used in your schema. The following is a simple code which will retrieve only a single component. If you are having a collection of components then you will have to use a for-each loop and modify the code accordingly.

<%
LinkResolver linkResolver = (LinkResolver) ApplicationContextProvider.getBean("LinkResolver");
GenericComponent linkedComp=(GenericComponent)comp.getContent().get("imageFieldName").getValues().get(0);
String href = linkResolver.resolve(linkedComp);
%>
<img src=" <%=href %>" alt="">
1

You are not providing enough information in your question. And from the information you do provide, I think you are on the wrong path.

If you are on the server and want to retrieve Binary content, then you need to call the DD4T BinaryFactory and pass in the URL or TCMURI of the binary.

This is usually done in the BinaryController where you have the Binary URL. Sample code below:

@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
public void getBinary(final HttpServletRequest request, final HttpServletResponse response) {
    String binaryPath = getBinaryPath(request);
    int publicationId = publicationResolver.getPublicationId();
    Binary binary = binaryFactory.getBinaryByURL(binaryPath, publicationId);
...
}

Then comes the delivery part, where you need to fill the Response object with the binary content and let it go back to the browser.

Naturally you would need caching to be done here, as you don't want to hit your BinaryProvider for each request. Some of the caching is done in the BinaryFactory, but you might want to implement some additional yourself.

Next, you will need to handle cache headers in request/response (if-modified-since, last-modified).

Finally, you will need error handling for corner cases (DB down, binary not published, exceptions from provider tier, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.