R
RailwayCelengan Babi

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!
Solution:
Yes, it works really well. In case anyone would like to use the same approach here's the code snippet for express/nodejs: ```...
No description
No description
P
Percy16d ago
Project ID: a764e147-c28b-4388-85d2-547de92d2fd0
CB
Celengan Babi16d ago
a764e147-c28b-4388-85d2-547de92d2fd0
B
Brody16d ago
please provide any errors you are getting
CB
Celengan Babi16d ago
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...
B
Brody16d ago
So you where able to successfully download the file over the private network?
Solution
CB
Celengan Babi16d ago
Yes, it works really well. In case anyone would like to use the same approach here's the code snippet for express/nodejs:
const url = 'http://xxxxx.railway.internal:3000/api/public/dl/C_izechY/data/xxxx.zip'; // This is the URL of a file hosted on Railway internal network using Filebrowser template (make sure to share the file first and set long expiry date)
const response = await fetch(url);

if (!response.ok) {
res.sendStatus(500);
return;
}

// Set headers
res.setHeader('Content-Type', response.headers.get('Content-Type'));
res.setHeader('Content-Length', response.headers.get('Content-Length'));
res.setHeader('Content-Disposition', 'attachment; filename=xxxx.zip'); // replace with your desired filename

// Pipe the response stream directly to res
response.body.pipe(res);
const url = 'http://xxxxx.railway.internal:3000/api/public/dl/C_izechY/data/xxxx.zip'; // This is the URL of a file hosted on Railway internal network using Filebrowser template (make sure to share the file first and set long expiry date)
const response = await fetch(url);

if (!response.ok) {
res.sendStatus(500);
return;
}

// Set headers
res.setHeader('Content-Type', response.headers.get('Content-Type'));
res.setHeader('Content-Length', response.headers.get('Content-Length'));
res.setHeader('Content-Disposition', 'attachment; filename=xxxx.zip'); // replace with your desired filename

// Pipe the response stream directly to res
response.body.pipe(res);
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.
B
Brody16d ago
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 code
CB
Celengan Babi16d ago
oh 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 👍
B
Brody16d ago
exactly
CB
Celengan Babi16d ago
Thank you Brody!
B
Brody16d ago
no problem!
Want results from more Discord servers?
Add your server
More Posts
error 13when i run "railway up" in the terminal of my project it says Permission denied (os error 13)Transferring a service from one project to anotherHow Can i transfer a service from a project to another project. it's a mysql database so i can't reIssue when deploying node app using dockerI'm having issues when I'm trying to deploy a node app with docker, when I build and run the image lFastAPI service health-check fails in IPV6I'm running a fastAPI service in railway. I setup a `/healthcheck` endpoint. It worked well when I eServer Response too slowI have Django, React application live on railway. I'm using Hobby plan. whenever I click through pDown only in DubaiHi Railway, Starting around 7.30 PM UTC +4, we can’t access our production instances. The URL is zeApplying chance is persistingI have this popup constantly appearing, even though nothing is being updated / changed. Anyway to geMySQL Memory UsageHey there, we just migrated to Railway and in the last 24h I saw that the memory usage is consistentRailway crashed after errors on trycatch?Is there any parameter to change in Railway so that it doesn't crash? because I'm using a trycatch tRailway having trouble connecting to local db upon deploymentHi. I recently deployed my node.js app on Railway and found out that during startup of my node.js apRedeploying service doesnt use updated Source Repo URLHi im new to railway so maybe this is a misunderstanding. I have started a project using a template rust deploy uses 10x more ram than local devhey guys, i have a rust api that is using 4-8gb of ram suddenly, now for rust that's unheard of conUnique variables for replicasHow can I assign a different token environment variable to each replica? Or have the replicas chooseDelete Strapi build and .cache foldersHello, how can I get a list of files in my railway project? I tried the command `railway run ls` buUnable to add repository to service that I'm a collaborator onI'm a collaborator on a github repo, and I'm trying to deploy a service on railway using that repo. Deploy angular project on RailwayI have angular project which I can build and run on my local machine perfectly. here is the link of Issue when deploying Typebot templateLooks like something went wrong and the train derailed... Hello, I have tried deploying both TypeboBun + Next JS 14 + Dockerfile run build failed timed outHi! The run build crashes due to timeout, please look, what's wrong with this? Service ID 9783c8b7-cExtremely expensive by previous standardsI've been using Railway for more than a year and a half, and for the first time I've seen such nonseI am charged twice for the same BDI have double database since the migration, and I am being billed twice as much, I have several data