How to download file from public folder?

hi everyone, i have some .rar files in public folder, and how to user can download them ?
i use FlowRouter and tried with this:

<a href="/download/lastest.rar" download target="_blank">Download</a>

but not work, it still download .rar file but empty and damaged file.

As long as [app_root]/public/download/latest.rar exists and is readable, that should work. Have you confirmed that the filesystem permissions on the stored file allow it to be downloaded? Maybe try with another type of binary file, just to rule out any issues your environment might have with serving up .rar files specifically. Are you proxying requests through a web server (e.g. nginx)?

@hwillson have any example ? i use nginx but dont know how to do that
i dont know how to confirmed that the filesystem permissions on the stored file too @@
please help !

Okay - backing up a bit then; how are you deploying your application (using mup for example) and where are you hosting it (Galaxy, Heroku, AWS, DigitalOcen, etc.)?

dear mr @hwillson i host on my private VPS, i use ubuntu + passenger + nginx.
i run meteor build .bin --architecture=os.linux.x86_64 for deploy.

To check permissions, SSH into your Ubuntu box. Find the location of your deployed app bundle, then take a look inside the public assets directory. In your case it will be something like:

cd [some_parent_dir]/programs/web.browser/app/download

Within that directory, list the file permissions using ls -l:

[server] /opt/testapp/app/programs/web.browser/app/download > ls -l
total 0
-r-xr-xr-x 1 meteoruser root 0 Apr 20 09:20 latest.rar

You just want to make sure your deployed downloadable files are set to be readable by whoever your web service is running as. In the above case for example the listed file is readable by everyone (take a look at Understanding Linux File Permissions if you need more info).

If that all looks okay, then something else is corrupting the download. Have you tried adding another type of binary file into your app for download, like an image or a PDF? If you can download other types of binary files than .rar files, then you might have a content-type issue with your web server. You might need to look into adjusting your mime types via nginx for example.

1 Like

how can i do this at localhost ? im using windows 10.
have any way simple ?
like publish public folder for all files in there available to download ?

Did you solve this issue? I am stucked, too.

Running on localhost, i need basic file download. Downloaded files are damaged but files on server are fine.

Did someone solve this? I am having the exact same issue!

Running on local host, I have my files in the public folder and made them chmod 777 so that Iā€™m sure it is not an issue of permissions. Still, no matter what the file format is, they get corrupted when trying to download them.

I have also made a post to Stack Overflow!

this resolve, we sould use .zip file replace for .rar.
other way, i create subdomain: public.domain.com and config public download files with nginx.
thanks so much !
this resolved !