Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to send a file to front-end from Rails server deployed in heroku ?

abijith asked in Rails

I have a Rails application with React in the front end and deployed in Heroku.

I am trying to send a file from the server to the browser side. I did saw the Rails "send_file" but it makes use of Rack::Sendfile middleware, which is not supported by Heroku.

To quote from Heroku's documentation:
"Heroku does not support the use of Rack::Sendfile. Rack::Sendfile usually requires that a front-end webserver like nginx or apache is running on the same machine as your app. This is not how Heroku is architected. Using the Rack::Sendfile middleware will cause your file downloads to fail, because it sends a body with a content length of 0."

And due to client requirements, I have to stick onto Heroku .
Please let me know of any works around for this.

Reply

Hi Abijith

Is there a good reason why your backend must "send" the file to your frontend?
I suppose what you would normally do in these cases is to make some kind of API which simply responds with the file in question. I believe that this could be done rather simple with respond_to (https://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to) instead of having to make a fully fledged API.

This solution should work regardless of which hosting provider you're using.

Mads

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.