0

I've got ROR application deployed on Heroku but the file upload doesn't seem to be working at all.

I do have multipart => true set up on the forms.

This is definitely working on my localhost environment.

Is there something that I need to enable to get this working?

Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168

2 Answers2

2

Heroku doesn't accept file uploads the last I checked. You'll need an Amazon S3 or something similar to accept the files. If you upload a file to Heroku, you can access it for the duration of the request via the Tempfile class, but it will not get saved.

https://devcenter.heroku.com/articles/paperclip-s3

https://devcenter.heroku.com/articles/s3

Sherwyn Goh
  • 1,352
  • 1
  • 10
  • 19
2

This error trips up a lot of people when they start using Heroku, me included!

The reason that you can't store files locally on Heroku is that this just isn't how Heroku works. Heroku takes a copy of your git repository and bundles it up into a "slug" which then gets run on their servers. Anything outside your slug (i.e. that's not stored within your git repo) will be lost when the dyno (virtual UNIX instance) restarts.

You can see this by firing up a console with heroku run rails c and creating and saving a new file using Ruby's File object. The new file will save correctly, and you can do things like require it or read from it, but if you close and reopen the console window, the file will have disappeared.

So if you want to store files that are being uploaded through a form, you need to use an external storage service. I like Amazon S3 as it's very simple to integrate with Heroku using Paperclip, as the links in the other answer mention.

GMA
  • 5,816
  • 6
  • 51
  • 80