Reading pdf attachments from repo

Enonic version: Enonic XP 6.14.1
OS: Windows 10

Hi,

I have created a repo and I posted some images and documents successfully. I have read those images and documents but I’m not sure how to display them in the view. Is there any library that can help me processing the binary data?

Regards.


Hi,

I’d like to be more specific with my question. I’ve seen in some examples that when the file or image is in the content repository you can use imageUrl or attachmentUrl to point to that file/image. How could I do that when the file/image is in a different repo?

Regards.

Hi,

imageURL or attachmentUrl methods are specific to the CMS solution in enonic. So what you need to do is to create a service that you can use to get the node and stream the attachment inside that node.

You can get an idea how you can do it https://bitbucket.org/openxp/lib-filesystem/src/master/ scroll down to the bottom of the page to see a streaming service example.

Sorry. I can’t get you a working example as I don’t know how you’re node content looks like.

//Runar

2 Likes

Thanks a lot for you answer. it seems it’s what I need.

Regards.

We also do something similar in the office-league app to stream images for the user profiles.

1 Like

Hi,

It seems that there is a problem when downloading that library.1

Hi,

I’m sorry but there was an error in the docs how to add the lib.

The error was in the dependencies part in build.gradle

This is the correct include that works:

include ‘openxp.lib.filesystem:0.9.5’

//Runar

1 Like

Hi Runar,

That’s the same that I had. I still can’t download it. :persevere:

Hi,
Can you paste in the content of you’re build.gradle file ? It works fine in my project that Im working on.

//Runar

1 Like

Hi,

Yes. I added it in build.gradle as a dependency but I get the same error message that in the previous screenshot.

Have you added the maven repository in your build.gradle?

repositories {
    maven {
      url 'https://dl.bintray.com/openxp/public'
    }
}

And the include should be :
include 'openxp.lib:filesystem:0.9.5'
(’:’ and not ‘.’ before filesystem)

3 Likes

Working now!! It was the colon. Time to play with the library!! :smile: Thanks a lot.

Hi guys,

I still haven’t been able to use the library. I get the error

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper

Could someone advise please?

Hmm… can’t help with the lib, but is’nt it really the example in the code you are interested in? You should not be reading/writing files in your use-case, but use repo if I have understood it correctly.

We also serve assets from the repo in the office league app, could be worth having a look at that code too?

Hi Thomas,

I’m new with Enonic so I’m trying different ways to do the same thing to see which way is better. Basically I have created a repo to store documents. I wanted to try that library and the way you do it in Office League as well. I’ve tried to install the filesystem library unsuccessfully (so I think I will leave this library for now). Following the approach in Office League I have stored files in the repo that I have created and I read them. I can read the documents but they are just binary data. I’ve seen that in office league u use a Java based Image Handler to process the images. For the project that I have to develop I need to work with documents only so I will leave the image testing for now, the question now is how can I process that binary data to display/download the documents (pdfs)?

Regards.

1 Like

Hi guys,

My code works with plain text files. I can save those files in the repo that I created and I can read them. The problem is when I want to store/read pdf files so I think it’s an encoding problem. This is what I do:

  1. When I upload the pdf files I use getMultipartStream in the portal library. Then I get a data-stream.
  2. Then I use the function binary in Value library to get a binaryAttachment java-type that I can store in my repo.
  3. To read the files I use getBinary in RepoConnection Library but the documentation doesn’t say anything about the return type.

Is this correct? Is there any enconding/decoding process in the middle? How can I display/download the read files in the client side?

Regards.

1 Like

You want to achieve what attachmentUrl does for content, but from a repo node, not content, right?

ref:
http://repo.enonic.com/public/com/enonic/xp/docs/6.13.0/docs-6.13.0-libdoc.zip!/module-portal.html#.attachmentUrl

1 Like

Exactly. That’s what I would like to achieve.

I think the answer is here:
https://discuss-3.enonic.com/t/services-streaming-a-response-from-a-file-in-a-service-controller/986/2

2 Likes

Thanks a lot for your help Chris. It was missing the contentDisposition. it’s working now.

Best regards.