shahryarjb
Hello, I am creating a LMS that lets the user to download file. The user need the file should send me his token and after validating I let him download whatever he needs.
Now how can I stop user from downloading directly? because files are uploaded by admin in ftp, and ftp path is in my server
I don’t know where I can start?
Thanks
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
wolfiton
You can start by storing your files in your application in the assets folder then add authorization that only one type of user can download unlimited that file(ex: admin can download but user can’t).
If this scenario doesn’t work, then you can create a field in the
user tablescalled plan. When a user pays you update the plan to paid. Then create a rule that only users with a paid plan can download files.If you want to be even more specific then you will have to create another table with all the files structure like this:
Then create a join between the user tables with the files tables and verify each user to what file they belong
Also you will have to setup a payment system paypal stripe etc.
Also this link may provide some help Phoenix file download
outlog
I would “proxy” the download through phoenix..
user buys product - you persist purchase in DB
user hits /download_file/#{file_id}
phoenix verifies the login/session and purchase and then reads the file (or streams it) and sends it to the user
if you have multiple files just show a list of files and then the user can download on /download_file/#{file_id}
that way the user never gets a direct link and if the user shares the link /download_file/#{file_id} - the “stranger” clicking it will fail on having a session/logged in - and will fail on the purchase.. so it doesnt work..
shahryarjb
I think I need this lines of code. this is the place I can start.
shahryarjb
would you mind explaining me more pleas? the stream file can be attractive, I haven’t used it before (streams)
cnck1387
To protect files in the past (and will be likely how I will do it in an upcoming Phoenix app) would be similar to how I do it with other tech stacks. I let nginx deal with it for the most part, while still doing authentication / authorization within Phoenix.
I’d keep the protected files outside of the main static assets folder.
Then have an “internal” location block in my nginx config like this:
Then for the download route at the Phoenix level, I’d authorize the download with a token and before I send the response, I’d set the
Content-Disposition,X-Accel-RedirectandContent-Typeheaders which basically tells Phoenix to let nginx serve the file.Here’s what that looks like in Python:
Of course you can change
foo.zipto whatever file you’re serving.I used this exact strategy like 5 years ago to serve a bunch of protected content and it held up very well.
shahryarjb
Hello, Thanks
I use this code:
I have a question , how can use
File.stream!instead ofFile.read!. I want to create chunks what I need and send to my userwolfiton
ASfter a google search found this
https://code.tutsplus.com/tutorials/working-with-file-system-in-elixir--cms-28869
Sample code from the first link:
shahryarjb
I saw these link before and test, but I had a error when I wanted to send file
send_resphas this errorif I change
|> send_resp(200, file.path)it has no error but I couldn’t to create my chunk size and send to my user, and is it my file streams?what about chunk?
I tested this code:
but I don’t know how can I change this line
|> send_resp(200, file)that sends stream file to user download managerwolfiton
Do you have a controller? or are you just trying to use static files?
Also here is a complete discussion on this Provide send_attachment/3 · Issue #1786 · phoenixframework/phoenix · GitHub
Try the
benwilson512
Seems like Plug.Conn — Plug v1.20.2 is the right call here. I see that this was tried earlier, what about it didn’t work?