Forum Discussion

omiaye's avatar
omiaye
New Contributor II
2 months ago
Solved

How to get filename from file reader


I need to get the name of the file read by the file reader snap and use it as part of the data downstream. Really the goal to save the file name as part of the data pulled from a file.  Screen snippet attached here.  I have spent some time looking into this but there is no obvious method to me. Please I will appreciate any input and recommendations. Thanks.

 

  • omiaye​ - The output of the directory browser does have the file name, screenshot below for references:



    If you're using a file reader and have multiple files, use snaps like copy/router/binary router (depending on your use case) and use the field "content-location" to get the desired file. Below screenshot for references again.



    If you're stuck and need help, please don't hesitate to reach out.


    Thanks.

     

    Regards,

    Darsh

2 Replies

  • SpiroTaleski's avatar
    SpiroTaleski
    Valued Contributor

    omiaye​ 

    Coupe of options how to get the filename: 

    1. Directly from the Directory Browser Snap: Put a Copy Snap after the Directory Browser Snap with Mapper on the second branch in order to map the name of the file. Field containing the name of the file should be names as "Name". And then you can join the stream after CSV Parser Snap.
    2. Directly from the File Reader Snap: Put a Binary Copy Snap after File Reader Snap with Mapper (input view to be in Binary type) on the second branch in order to map the name of the file. Two fields that you can look up in order to get the file name: content-disposition or content-location. You will need to utilize the SnapLogic functions in order to extract the filename and then you can join the stream after CSV Parser Snap.

    BR,

    Spiro

  • darshthakkar's avatar
    darshthakkar
    Valued Contributor

    omiaye​ - The output of the directory browser does have the file name, screenshot below for references:



    If you're using a file reader and have multiple files, use snaps like copy/router/binary router (depending on your use case) and use the field "content-location" to get the desired file. Below screenshot for references again.



    If you're stuck and need help, please don't hesitate to reach out.


    Thanks.

     

    Regards,

    Darsh