send_file - SSL

Hello,
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: "myapp.com"],
  load_from_system_env: true,
  url: [host: "myapp.com"],
  http: [port: 80],
  force_ssl: [hsts: true],
  https: [    
    port: 443,
    otp_app: :myapp,
    keyfile: Path.expand("/etc/letsencrypt/live/myapp.com/privkey.pem", __DIR__),
    certfile: Path.expand("/etc/letsencrypt/live/myapp.com/cert.pem", __DIR__),
    cacertfile: Path.expand("/etc/letsencrypt/live/myapp.com/fullchain.pem", __DIR__)
  ]

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

filename = "my/file/exists/here.pdf"
conn
|> put_resp_content_type("application/pdf", nil)
|> put_resp_header("content-transfer-encoding", "binary")
|> put_resp_header(
    "Content-Disposition",
    ~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.

Thanks

1 Like

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

check that ssl is correct using https://www.ssllabs.com/ssltest/

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

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

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