Jngai1297
Jngai1297

Reputation: 2495

Carrierwave add pictures on heroku

I added pictures locally in my machine in rails console, obviously when I push everything up to heroku I lost all of my fake data.

I head into heroku console to create 3 records

This is what I did

b = Restaurant.find(2)

and then

b.picture = File.open("Users/judyngai/Desktop/spukiesoutside.png")

The picture mounting is done through carrierwave and rmagick

I am getting this error,

Errno::ENOENT: No such file or directory - Users/judyngai/Desktop/spukiesoutside.png 

The file does exist and it is on my desktop. My local server can see it but obviously heroku can't. How do I add pictures manually on heroku console ?

Upvotes: 0

Views: 336

Answers (2)

McFadden
McFadden

Reputation: 1630

As Gavin said, Heroku's file system is (effectively) read-only. There are some exceptions to this (the tmp directory), but in general understand that any files you write to the filesystem may not be there on subsequent requests. Here's the relevant Heroku documentation: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

As far as an alternative, I recommend uploading directly to S3, and having your app fetch the files from there. Since Heroku runs on Amazon's EC2 network, it is blazingly fast if you need to read files into your app from S3. If you'll be serving them up to the user you can do that directly from the S3 bucket or through Amazon CloudFront.

The best tutorial I've found for this is Ryan Bate's RailsCast: http://railscasts.com/episodes/383-uploading-to-amazon-s3

It's a pro episode, but well worth the money.

He has quite a few other episodes of his you might find interesting. Search his site for "uploading" and you'll find a lot of useful tips and tricks.

Upvotes: 4

Gavin Miller
Gavin Miller

Reputation: 43875

Heroku doesn't allow file storage, you'll need to push to S3 or another file storage service.

Upvotes: 2

Related Questions