Heroku File Storage
Asked Answered
T

3

48

Heroku only has 100MB of file storage, right? I'm making a low-level rails app and I really like Heroku, but if my app allows each user to upload one picture, I may run out of space quickly...is there a simple solution that will allow me to have alternative file storage for profile pics or something of the like?

Tannenberg answered 11/7, 2011 at 21:45 Comment(2)
While you do want to use S3 on Heroku (since the file space is only temporary, and does not persist) for storing things like profile pictures (see Codeglot's answer below), I do want to point out that the 100MB limit is only for the slug (the compiled source and gems of your application). Your /tmp directory can actually hold very large files (I think I've seen talk of 4GB being alright to store there temporarily). But, again, you will lose whatever is there if your dyno restarts, so it's only meant to be used as a temporary storage space, not a permanent one.Pneumatics
in addition see the Heroku dev center article here on the topicArmure
A
21

See this blog post

In your model.

has_attached_file :picture, 
                   :styles => {:large => "275x450>"},
                   :storage => :s3, 
                   :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                   :path => "appname/:attachment/:style/:id.:extension"

In s3.yml in your config dir:

    development:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

    production:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

Then go signup for a bucket at Amazon S3: http://aws.amazon.com/s3/

Authenticity answered 11/7, 2011 at 21:48 Comment(2)
link is dead. Do you know if there is a new one?Hypothyroidism
@DonalRafferty It is still on wayback machine.Mantel
W
24

I would recommend you to check heroku add-on solution which is https://addons.heroku.com/cloudinary. You will get 500MB for free and easy heroku integration.

For RoR app you can check: https://devcenter.heroku.com/articles/cloudinary#using-with-ruby-on-rails

There is also documentation for Nodejs and Django.

Wedekind answered 29/9, 2014 at 12:17 Comment(1)
I found Cloudinary to be a perfect solution, it now provides 10 GB of free storage. Also, definitely check this django app: github.com/klis87/django-cloudinary-storage, it requires only changing some settings unlike the original Cloudinary app alone which requires changing code in models, views, and templates!Williswillison
A
21

See this blog post

In your model.

has_attached_file :picture, 
                   :styles => {:large => "275x450>"},
                   :storage => :s3, 
                   :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                   :path => "appname/:attachment/:style/:id.:extension"

In s3.yml in your config dir:

    development:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

    production:
      bucket: bucketname
      access_key_id: key
      secret_access_key: key

Then go signup for a bucket at Amazon S3: http://aws.amazon.com/s3/

Authenticity answered 11/7, 2011 at 21:48 Comment(2)
link is dead. Do you know if there is a new one?Hypothyroidism
@DonalRafferty It is still on wayback machine.Mantel
R
2

Yes, the simplest solution is to use the api.imgur.com, which allows you to upload 1250 images for free per hour.

You just need to register and get your client id then you need to send post request to

https://api.imgur.com/3/upload

with the image data as form data. Then you get a link of the uploaded image in response data which you can store it in database and then you can access the image like any other image with the link from front end.

more here:

Imgur API docs link

Radiator answered 5/7, 2020 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.