Announcement

Collapse

Mirth Connect 4.1.0 Released!

Mirth Connect 4.1.0 is now available as an appliance update and on our GitHub page. Mirth Connect 4.1.0 includes new features such as new event log messages, additional fields to the Welcome to Mirth Connect screen, new information included in alerts as well as many smaller changes, updates, and improvements. This release also contains several improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

SFTP Reader to read csv and pdfs from the same sftp location

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SFTP Reader to read csv and pdfs from the same sftp location

    HI All,

    Trying to figure out how to do a rather simple task, but running into a wall. The task itself is this:
    - we need to read a csv file with some data lines in it, one of the fields is a pdf filename that then needs to be read either as Base64 (or binary and then converted to Base64) from the same sftp folder to be associated with the csv record read earlier.

    For the life of me I can't figure out how to do it all in one ftp reader channel.
    Current solution is to set Filename Filter Pattern to "*.pdf", read all pdfs as base 64 (binary), then use a custom java sftp function to read (as text) and parse the csv file once sourceMap.get("pollComplete") == true. This works if there is at least one pdf, otherwise the channel quits before it gets to the destination which reads the csv.

    Alternatively I can set Filename Filter Pattern to *.csv to read the csv as text, but then there appears to be no way to send extracted filename to sftp reader to get that particular file. Tried to use custom java sfto function to read pdfs in a destination, that works, but then converting read bites to Base64 (used FileUtil.decode(data); for that) doesn't appear to work.

    Is there a way to read csv and then send read lines to an sftp channel line by line for it to extract pdf filename from input and use that as Filename Filter Pattern to read one particular file? I think just sending the filename would work for us as well.

    Thank you, any input would be greatly appreciated!

    P.S. I can set Filename Filter Pattern to *.* and read pdfs and csv in one go, but then it isn't clear how to convert csv from binary to text so I can parse the lines in it...
    Last edited by sfurman; 07-27-2022, 10:21 AM.

  • #2
    Your SFTP reader channel can read the CSV.

    In any transformer manually call jsch (the underlying java stuff for SFTP that mirth users) and go get the file the csv line mentiones. There are examples here on the forum how to run jsch.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Originally posted by pacmano View Post
      Your SFTP reader channel can read the CSV.

      In any transformer manually call jsch (the underlying java stuff for SFTP that mirth users) and go get the file the csv line mentiones. There are examples here on the forum how to run jsch.
      Hi pacmano,

      Thank you for your reply! I actually tried that, this was my first solution, the problem with that was converting the pdf bites jsch read into Base64 string. I'll try again and will post the actual error I get trying to convert resulting Base64 back into PDF and then view it. Hopefully there is an example of using jsch to read pdf and convert to Base64 here?

      Again - thank you for helping me with this!

      Stan

      Comment

      Working...
      X