Generate S3 URL

Hi everyone, :wave:

I’ve set up an S3 bucket and can upload/download files in my N8N workflow.

What I need now is to generate a secure, time-limited download URL for the file, rather than downloading it directly.
The goal is to send this URL to Budibase, where it will be linked to a download button.

I guess what I need to do is generate a pre-signed, expiring download URL but despite seeing the threads about that, I can’t find or do a working workflow.

My “read” request in budibase gives me this (anonymized):

[
  {
    "Key": "folder1/file1.csv",
    "LastModified": "2023-06-29T07:45:39.000Z",
    "ETag": "\"abcdef1234567890abcdef1234567890\"",
    "Size": 65400,
    "StorageClass": "STANDARD",
    "Owner": {
      "ID": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z"
    }
  },
  {
    "Key": "file2.csv",
    "LastModified": "2023-06-29T07:45:20.000Z",
    "ETag": "\"0987654321fedcba0987654321fedcba\"",
    "Size": 65400,
    "StorageClass": "STANDARD",
    "Owner": {
      "ID": "9z8y7x6w5v4u3t2s1r0q9p8o7n6m5l4k3j2i1h0g9f8e7d6c5b4a"
    }
  }
]

Any guidance on how to achieve this securely would be greatly appreciated!

Thanks in advance for your help!
Joachim

PS: Found this thread but did not help. :confused:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Joachim_Brindeau,

It would be handy to pop a vote on that feature request, To generate the link we don’t have an example for that at the moment so it would be a case of following the Amazon documentation on how to make the signature which could be tricky.

If I get a chance I will take a look and see if I can work out a quick script to do it if the example in the other post isn’t working.

Are you also AWS S3 or an S3 compatibale storage option?

I was also wondering about that. the closest solution I came up with is installing S3 CLI utility, attaching it to you S3 bucket and then calling Execute Command node from n8n.

Here’s a fun hack!

  • Only works in self-hosted version of n8n
  • NODE_FUNCTION_ALLOW_EXTERNAL=@aws-sdk required.
  • Tested in v1.48.0

How it works

  • It uses the @aws-sdk/client-s3 which is available to n8n. See docs here.
  • However this version of @aws-sdk doesn’t come with the @aws-sdk/s3-request-presigner which is required for signing urls. See docs here.
  • We can hack around this by installing this library via npm using the execute command.
  • You can require libraries via absolute paths so that’s how we bring it in to the code node.

Good to know

  • require('@aws-sdk') in code node doesn’t work because n8n doesn’t come with the “full fat” AWS package. It may have in the past but I think this was changed at some point.
2 Likes

Hi @Joachim_Brindeau,

Solution of @Jim_Le is really helpful and clean. However, if you are not using self-hosted version, you can find a Lambda function for your need. After that it can be run on n8n via “AWS Lambda” node.

I hope it helps.

2 Likes

Thanks a lot for your answers! I had to postpone this workflow and will look into it next week. Thanks a lot for the solutions offered!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.