joshua-bouv

joshua-bouv

Using a phoenix framework application as a download server

This is probably a very silly question, but I’m still interested in the answer nonetheless! I’m also fairly novice so apologies for any outrageously silly assumptions I might of made!

Part of my application requires allowing authenticated users to download files uploaded by other authenticated users (around 1-10mb each).

The frequency (kinda guessing here) could be once every several minutes to a maximum of a few simultaneously, and each download will likely be serving a different file. The download speed doesn’t really matter.

Is creating an application to handle this in elixir/using phoenix a very silly idea and I should use some other language/framework or would it be fine?

I would likely have the files stored on a separate server with a very high bandwidth cap and lots of storage space, which I guess would also house the application that handles incoming download requests.

I’d then hopefully have cloudflare route a web request either to my web servers or download server to prevent my transfer caps getting obliterated on the web servers. (I’m hoping this is a thing I can do, never really used cloudflare before!)

Thanks in advance!

Most Liked

dmitriid

dmitriid

I’m doing this for a low traffic personal library (me and my mum :slight_smile: )

The download controller does basic auth to see if the user has the right to download the file, and then sends the file.

Something along the lines of

# for path /file/:id
# see if user is in session and/or authenticated, this can be done on plug level
# then find if the file exists and the user has access to it
# then 

        conn
        |> put_resp_content_type(... your content type ...)
        |> put_resp_header(
          "content-disposition",
          "attachment; filename=#{whatever filename you come up with}"
        )
        |> send_file(200, file)

I don’t see why this wouldn’t work even for significantly more users than a few at a time.

EDIT: Of course, if this becomes a problem, then other solutions like having them stored under one-time keys in an object storage as described above etc. would work better

victorbjorklund

victorbjorklund

Don’t see why this wouldn’t be possible. I personally probably would just upload and download from an object storage (like Linode or Digital Ocean). That way uploads and downloads should be faster (since they can probably scale easier). And usually the bandwidth and storage cost is lower than if you store it directly on a server.

You can then use Phoenix to generate the time-limited token to upload directly to the object storage and if only certain users / only logged in users you can generate a token to download the file too. If it’s less sensitive you can put a CDN infront of it like Cloudflare to make it even faster/cheaper (technically you can’t use cloudflare only for files like that but unless you are doing many TB per day they probably won’t care).

dimitarvp

dimitarvp

As an education project – sure. But I see no reason why you wouldn’t just put the files somewhere and put the Caddy server software in front of them.

Or, as @victorbjorklund says, use various cloud providers for absolutely free unless somebody makes it a point to go download them 24/7 just so you can accumulate a cloud bill. :003: Which is extremely unlikely.

Last Post!

joshua-bouv

joshua-bouv

Thank you to everyone who responded :heart:

I’ve never heard of object spaces before so thanks for opening my eyes! Will do some more digging and may end up going that route, whatever is the cheapest I guess!

Will start off by giving it a go in elixir though and see how that works out for me and also for the sake of learning something new!

Thanks again!

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement