Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yosle opened this issue May 23, 2023 · 0 comments
Open

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

yosle opened this issue May 23, 2023 · 0 comments

Comments

@yosle
Copy link

yosle commented May 23, 2023

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 })
  });

    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant