Skip to content

How to download remote file from URL in smart action? #1006

Description

@yosle

Expected behavior

In a smart action with a form that has a enum , the user selects an option and execute the action, after data is fetched I want to download a file from a remote url (a cloudinary hosted file) and return the downloaded file as a response

Actual behavior

Not returning the file

Failure Logs

I could not find any documentation about how to do this

Context

//rest of the code in users collection
   {
      name: "Download User Documents",
      type: "single",
      fields: [
        {
          field: 'Download User Documents',
          description: 'Select Document Type',
          type: 'Enum',
          isRequired: true,
          enums: [
            "Carta del Banco",
            "Certificado de Proyecto de Trabajo",
            "Certifico de No Adeudo Fiscal",     
          ],

        }
      ]
    },
...//rest of the code
    ```
    The action code
    ```
    
router.post('/actions/download-user-documents', permissionMiddlewareCreator.smartAction(),
  (req, res) => {

    // Get the values of the input fields entered by the admin user.
    const attrs = req.body.data.attributes.values;
    let selected_document = attrs['Download User Documents'];
    console.log("selected document ", selected_document);
 //Logic where I calculate the right file and get the url

    res.sendFile(fileName, options, (error) => {
      if (error) { next(error); }
   //HOW TO SEND THE FILE BACK IF I ONLY HAVE AN EXTERNAL URL??
    });
    // res.send({ success: "Accion exitosa selected_document " + selected_document })
  });

    ```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions