Articles in this section

Get the file name and size of FTP exports

You can get the file name and size for FTP parsed files and blobs. integrator.io generates the file name and size metadata properties for FTP exports. 

Get the file name and size - FTP parsed files

For FTP files to be parsed, you must perform the following tasks to get the file name and size:

  1. Add the file name and size in a preSavePage hook
  2. Reference the file name and size

Note: If you’re processing multiple JSON files from one FTP export, preserve the source file name and size for each record for passing to the destination app or for error handling later.

1. Add the file name and size in a preSavePage hook

First, you must add the code to parse the file name and size metadata properties for your records within a preSavePage hook.

  1. In Flow Builder, click the Define options (+) button on the export and then click the HooksHook button ) button. The Hooks panel opens.
  2. In Hook type, select Script.
  3. In the Pre save page section, click the Create script (+) button. The Create script panel opens.
  4. In the General section, enter a name for your script.
  5. In the Script content section, in Insert function stub, select preSave page.
  6. In Edit content, write the code to generate the file name and size for each record. (See the following example.) Click Save and close.

Example script

In the example below, the file name value is given as fileName and the size value is given as fileSize. You can specify any field key name you prefer, but you must refer to it throughout your flow by that name.

function preSavePage (options) {
  // sample code that simply passes on what has been exported
  if(options.data && options.data.length>0){
    for (let i = 0; i < options.data.length; i++) {
      options.data[i].fileName=options.files[i].fileMeta.fileName;
options.data[i].fileSize=options.files[i].fileMeta.fileSize; } } return { data: options.data, errors: options.errors, abort: false, newErrorsAndRetryData: [] } }

2. Reference the file name and size

After you have added the file name and size in a preSavePage hook, you can reference and access the field fileName and fileSize anywhere in your flow where handlebars expressions are allowed.

Example 1: Reference in import mapping

Assuming a simple exported CSV file with column a (helpdesk ID) and column b (ticket description), after the preSavePage hook, the record structure might look like the following example: 

{
  "data": [
    {
      "a": "CUST_445",
      "b": "Unable to save financial report",
      "fileName": "File_Provide_1.csv"
"fileSize": "7890" } ], "errors": [], "abort": false, "newErrorsAndRetryData": [] }

The file name and size are now available for mapping fields at the import step: 

Note: In the Advanced Field Editor (AFE 2.0), the file name and size are not actual values but an indication of what they're like.

Example 2: Reference in a custom header

You can reference the file name and size in the custom header using a Handlebar expression.

If required, you can view the file name and size in the debug logs.

 

Get the file name and size - FTP blobs

For FTP blobs, you can get the file name and size metadata properties by specifying values in the Import step using a Handlebar expression. You don’t need to execute a hook for blobs. 

  1. Open the import step.
  2. Wherever you want to make use of the file name or size on the import step for the FTP blob export, use a Handlebar expression as shown in the example.

Example: Configure HTTP headers

If you have an FTP blob export and an HTTP blob import and the HTTP import is expecting integrator.io to send the file name and size in the header, then you can configure the file name and size in the header using Handlebar expressions.

If required, you can view the file name and size in the debug logs.

Get the file name during error handling

The exposed file name is helpful if you have multiple exports in a flow with similar data files and want to know which file is generating an error. Rather than searching through every file in your export, you can view the file name in the error message.

To view the file name in the error message:

  1. Open the export.
  2. In the Advanced section, click the edit icon next to Data URI template to open the Handlebar editor. In the Advanced Field Editor (AFE 2.0), enter the following Handlebar expression.
    {{record.fileName}}
  3. Click Save and close.
    The Handlebar expression is displayed in the Data URI template.

Note: When you add the file name to the Data URI template setting of the export, the value will appear in any error message.

Filename added to the Data URI template in the Advanced section of the export step
Filename visible in an error message
Was this article helpful?
0 out of 0 found this helpful

Comments

3 comments
Date Votes
  • Hi Kathyana,

    Thanks for the article. I was wondering if there is a way to get the size of the parsed file? 

    Thanks,
    Dee

    ================================
    UPDATED 4/26/2022: Conversation continued at FTP export - looking for file size and content type.

    0
  • Hi Kathyana,

    Thanks for this article.  It helped me make the handlebar {{record.fileName}} worked.

    Best regards,

    Raul

    0
  • Hi Raul Bernales

    No problem! Glad to hear I could be of help. Feel free to comment on any article if you have questions, ask in the community, or reach out to writers@celigo.com

    Thanks, 

    Kathyana

    0

Please sign in to leave a comment.