image uploads getting wiped out after deploy - ruby-on-rails

I am using carrierwave for image uploads. I am storing the images at /public/uploads
When I deploy to heroku, images that were uploaded and saved previously are wiped out.
How can this be avoided?

Turns out I can't upload images to heroku.
I have decided to use cloudinary for the time being.
I will probably switch to S3 eventually.

Related

Heroku Images gone

After updating images for many products on HerokuApp, I came back some minutes later to see that all images of the products but two are missing?
Is this normal or is this fixable?
Thanks!
Heroku doesn't allow you to save images to it due to its ephemereal storage unless they're a part of your assets folder and precompiled. For uploading images you need to tie it into AmazonS3 (or some other image store) because only the database data persists. Here's a heroku dev guide that shows how to use AmazonS3 to store images and why they can't be saved on Heroku's platform itself:
https://devcenter.heroku.com/articles/active-storage-on-heroku

Exporting existing uploaded images in Refinery to Amazon S3

I have an existing Rails RefineryCMS application, which have been running for quite some time. It has alot of image and document uploads, which always have been uploaded to the local filesystem.
But we are moving to Heroku, then this will be a problem, since Heroku doesn't persist these files.
So, we need to get all the existing images and document exported to a Amazon S3.
How could we achieve this?
Would it be plain simple as just copying over the existing files from the current production environment to the S3 bucket?
Kind regards
The plain solution was just to copy the existing folders that are generated by fileupload from Dragonfly in "app/public" to Amazon S3.

heroku paperclip images appear but then disappear

I uploaded my app to heroku. The app was built with ruby on rails and had the activeadmin and paperclip gem installed. The files are configured properly and i was able to upload images using he active admin gem. this worked perfectly loaclly and worked fine on heroku until i uploaded more images, now all the images have disappeared. Any ideas on how this can be sorted?
Heroku has an ephemeral filesystem.
That is because each running dyno is an independent container (much like docker) which shared nothing with other dynos, and is destroyed when the app is restarted/deployed.
So any file written on disk will be lost when the dyno is restarted, and is not recoverable.
You need to configure paperclip to upload images to a dedicated file storage system like Amazon S3.
You can't store images on heroku, or anything for that matter. Your uploaded files are available for temporary use only, long enough to process them away to cloud storage elsewhere.
http://cloudinary.com/ offers development accounts for free; https://aws.amazon.com/s3/ has become ridiculously cheap and gives new devs a long free trial. There are other resources but ultimately you have to choose storage which isn't transient.
You can use gems like carrierwave, or attachinary to easily access and store with either of those storage locations.

Uploading image into assets folder

I was following this guide for uploading images with PaperClip over ActiveAdmin:
File upload with Activeadmin Rails using paperclip
Everything is working fine, but I was wondering, after I upload image, how to redirect it to be uploaded into /assets/images/ instead only in database?
You don't.
It won't work anyway. assets/images is a source directory for rails asset pipeline. On your production server, the images are not used from there but from another folder where they have been updated by the pipeline (typically getting a name with a linked timestamp, so that the browsers can cache them properly).
To make this work you would need to upload them to the assets/images, then run again the asset pipeline, which would be... weird.
If you don't want to store them in the public folder, look at an external storage like S3 (sample using Heroku: https://devcenter.heroku.com/articles/paperclip-s3).

Rails] Images erased after a new commit on heroku

I'm using Carrierwave to upload images, and my app is on Heroku right now.
Images are uploaded successfully unless I push a new commit to heroku. Images that I uploaded before a push seem to be erased when a new commit comes in. Does anyone know the reason behind and how to fix this issue?
Update:
The problem becomes, using carrierwave on Heroku without a storage server like Amazon EC3. Heroku does not save files in public folder, where carrierwave uploads by default.
app/uploaders/image_uploader.rb:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
And you need to change this to somewhere in the tmp folder in order to preserve your image files after each commit. I tried to change it to
"#{Rails.root}/tmp/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
But it does not work. I checked on my local environment, and the image is stored in the right location successfully. So I guess if I just set the routes to the right location, this could work. Could someone help me with this?
Since Heroku does not allow storing static files (unless it's associated the application itself), you should make Carrierwave upload to a remote repository (e.g. Amazon S3) using fog. Everytime a user uploads a file, the file will be automatically uploaded to your S3 storage instead of Heroku.

Resources