0

I want my angular app to show a list of PDF files which were previously indexed by a solr server. The PDF file should then open in my app (pdf-viewer installed and working with external PDF files like this one. Since Angular can't access/display local files I thought I might use a node API which I'm currently using in my angular app to get some data from a db to also get the list of PDF files. I just don't know how...

The indexed files have three fields (fileName, fileDir, fileAbsolutePath) which I can get by using the solr query (https://myServerAdress/solr/CoreName/select?fl=fileDir%2C%20fileName%2C%20fileAbsolutePath&q=*%3A*) in case it's relevant.

I don't need a exact tutorial on how to do this. A rough approach on how to do this would be sufficient and very helpful!

Screenshot and notes of the actual goal

naitunix
  • 49
  • 1
  • 11
  • What's the relationship between "indexed files having three fields" and the PDFs? Why don't you make a list of links to URLs like `https://myServerAdress/solr/CoreName/select?fl=fileDir%2C%20fileName%2C%20fileAbsolutePath&q=*%3A*`? – ulmas Nov 22 '19 at 15:09
  • @ulmas I want to open the PDF files in my Angular app (pdf-viewer installed and working with external hosted pdf files) when I click on them. A list of solr queries would return a JSON file with the information of the PDFs (name, directory, etc.) and not the PDF itself. I will edit the question, to mention the first part. Thank you. – naitunix Nov 22 '19 at 15:26
  • You have to map the file name indexed to a path that your node application have access to - then make a request to your node application that returns the file. Either directly or through something like `X-Sendfile`. – MatsLindh Nov 22 '19 at 19:17
  • @MatsLindh that was the answer I was hoping to recieve. Thank you. I will mark it as the correct answer if you make it as such. – naitunix Nov 25 '19 at 08:45

1 Answers1

0

You have to map the file name indexed to a path that your node application have access to - then make a request to your node application that returns the file. Either directly or through something like X-Sendfile.

Exactly how you do this will depend on the framework you're using in node.

Solr does not have any method to retrieve the actual raw file content for serving, so the absolute path you've indexed (or file name if you have a static dir) will have to be used. Be careful about not serving files or documents outside of your intended path.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Can you tell me where to read how to "map" the files? I can't seem to find it, especially not in combination with node express. – naitunix Nov 26 '19 at 12:14
  • See https://stackoverflow.com/questions/25463423/res-sendfile-absolute-path - it tells you have to send a file given from its absolute path with express – MatsLindh Nov 26 '19 at 20:53
  • Yea, that is what I did, I just forgot to post that I found something. Thank you so much. – naitunix Nov 28 '19 at 13:12