Fetching a file hosted on Filebrowser via Private Network
So I currently have a file that I am hosting using Filebrowser template.
The file has a download link that can be accessed via public URL without any problem.
But whenever I try to download the file from another service in the same project using internal private network, the file couldn't seem to be downloaded.
What I did was that I simply changed the public URL into the private one, like so:
http://heroncopier-download.railway.internal:3000/api/public/dl/xxxxx/xxxxx.zip
As you can see in my above example, I did already changed the https into http and I also added the port after the internal URL.
Does anyone have any clue on how to solve this?
Thanks!
![No description](https://cdn.answeroverflow.com/1224904382412492851/image.png)
![No description](https://cdn.answeroverflow.com/1224904382672277514/image.png)
Solution:Jump to solution
Yes, it works really well.
In case anyone would like to use the same approach here's the code snippet for express/nodejs:
```...
11 Replies
Project ID:
a764e147-c28b-4388-85d2-547de92d2fd0
a764e147-c28b-4388-85d2-547de92d2fd0
please provide any errors you are getting
Hi @Brody, nevermind. I got mixed up between the native fetch() function and the one that is provided by node-fetch npm package.
This post gave me the clue: https://stackoverflow.com/a/74611064
Stack Overflow
Npm - fetch vs node-fetch?
These package names are pretty confusing, they seem like they do the same thing yet 'fetch' looks to be abandoned yet not marked as deprecated (last commit 3 years ago). Judging from the download c...
So you where able to successfully download the file over the private network?
Solution
Yes, it works really well.
In case anyone would like to use the same approach here's the code snippet for express/nodejs:
Above code lets your server fetches the file from other service in the same project via Railway's private network.
You can also install npm package such as express-rate-limit to prevent anyone from abusing the download endpoint (so not to let them waste your egress bills, just make sure to setup x-forwarded-for header config properly on the limiter)
Using this approach, the file can only be downloaded via endpoint that you can control.
It is not maybe state-of-the-art solution but it works for my use-case for now.
i might even go as far as to turn
http://xxxxx.railway.internal:3000/api/public/dl/C_izechY/data/xxxx.zip
into an environment variable like DOWNLOAD_URL
just in case you need to change it then you wont have to edit codeoh true, that's a neat approach. I'll do that. so at least whenever i need to change something, I don't have to push any changes in the code
👍
exactly
Thank you Brody!
no problem!