send_file - SSL

I just configured my app with SSL and i see that i have problem with downloading files. On my config i have this:

  force_ssl: [rewrite_on: [:x_forwarded_proto], host: ""],
  load_from_system_env: true,
  url: [host: ""],
  http: [port: 80],
  force_ssl: [hsts: true],
  https: [    
    port: 443,
    otp_app: :myapp,
    keyfile: Path.expand("/etc/letsencrypt/live/", __DIR__),
    certfile: Path.expand("/etc/letsencrypt/live/", __DIR__),
    cacertfile: Path.expand("/etc/letsencrypt/live/", __DIR__)

I have a route that I generate file and i send the file like this:

filename = "my/file/exists/here.pdf"
|> put_resp_content_type("application/pdf", nil)
|> put_resp_header("content-transfer-encoding", "binary")
|> put_resp_header(
    ~s[attachment; filename="file.pdf"]
|> send_file(200, filename)

The issue is because without SSL everything works fine, but when i added SSL in the route that i generate files, it doesn’t return the file.


1 Like

Any sample project in GitHub to speed things up for whoever would like to help you?

check that ssl is correct using

NB you have multiple “force_ssl:” in your config you probably want:

force_ssl: [rewrite_on: [:x_forwarded_proto], hsts: true, host: “”],

additionally you are using x_forwarded_proto which suggest you have something in front of the phoenix app? what is that? (nginx? etc?)

1 Like