It looks like the HTML5 download attribute is supported on every browser now, and I was wondering if there are any advantages/disadvantages to using this instead of creating a link and using send_file in a controller with Rails.
It looks like the HTML5 download attribute is supported on every browser now, and I was wondering if there are any advantages/disadvantages to using this instead of creating a link and using send_file in a controller with Rails.
send_file is both more versatile and more efficient.
Its main advantage is that it uses the X-Sendfile response header. What that does is offload the streaming process of the file from Ruby to the server (e.g. Nginx or Apache) which is optimized for high-throughput content delivery.
Plain 'download' links save the target regardless of what's displayed on it. This could be a problem if, for example, the target is session-protected, and the session expires before you click the link. You'd end up saving the login page without knowing it. With send_file you can dynamically initiate the download if the session is ok, or redirect to the login page otherwise.
send_file also lets you specify a meaningful file name dynamically, so if your link points to, say, /users/42, you could set the download name to be "John Smith.csv" instead of the cryptic "42".