I don't want to have to configure imagemagick but want to use a gem to be able to upload a picture from a form and put it into a database. Are there other options out there? I tried dragonfly and carrierwave but they require ImageMagick.
I often use Blitline which allows we to me to make any edits to the image (if needed) and then I have Blitline store it in an Amazon S3 bucket and place the image url in my database to save space in the database.
Related
How would I process a file before it's uploaded using activestorage. I need to be able to modify an svg file's content before it actually gets uploaded to S3. Can't seem to find any callbacks.
There is no way to do this natively with ActiveStorage. It's the major drawback with using ActiveStorage.
As far as I know, the only way to modify an upload is to create a variant of the original upload after it is created...which creates a (completely different) variant image based on the image that was originally uploaded.
ActiveStorage is easy to setup but, after using it with a few applications, Carrierwave..etc seem like better options.
In addition, if you want to upload in a background job, ActiveStorage is a pain.
I configured active storage to upload has_one_attached :image to Amazon S3.
product.image.attach(io: open(img_url), filename: "file.jpg")
But I want to optimize images: compress them or convert to .webp
I have mini-magick gem which i can use to modify images.
So can I dynamically modify image from url before uploading to Amazon?
Or all can I do is to save image from url, process it and then do attach? (It is so slow when I have millions of images)
According to ActiveStorage, it supports transformation, so you could try using https://github.com/janko/image_processing with mini magick or libvips convert method to transform the image before saving it. Or at least that's what i'm trying to do atm.
If i manage to do it I'll post it here.
Good luck
In Rails, I am using s3_direct_upload gem for asset(doc file) upload. Right now if I try to upload an image file as a different asset, it is directly uploading to s3. I need to disable this option for image upload and it should be enable only for document upload.
s3_direct_upload is provides form helper methods to upload images to s3 directly. like this s3_uploader_form. It just reduces your jquery_file_upload and s3 configuration.
But you can still upload image to your local file system. Using simple form_tag. i.e. When you want to upload images to s3 use s3_uploader_form syntax and when you want to upload images to local file system then use simple form_tag or any other rails provided form syntax.
For uploading images using ajax use remotipart gem with simple form syntax.
I have an S3 bucket setup already, it contains images of a photo gallery, uploaded from my Rails app using PaperClip. Images are accessible via some arbitrary URLs like: http://s3.amazonaws.com/oldbucket/images/files/000/001/920/original/40a6885fc09c8ed4e1e3745d7f7fb770.jpg?1415766995.
Kindly advice me the best option considering following requirements:
I have to copy those images to another S3 bucket in another AWS
account
I want to make the new image URLs according to specific
patterns, like: .../newbucket/{userid}/{galleryid}/{image-size}.jpg
I want to create multiple versions of each image, according to size
(original, thumbnail and icon)
Any options using Rails gem or software that would do above would be helpful.
Thanks
For this you need to add carrierwave gem for saving image from remote url. You can also do with paperclip.
First create a seed file without adding carrierwave uploader to your app. I am considering User as model and avatar as image.
User.all.each{|u| puts user.avatar.url}`
Now remove paperclip and add carrierwave This will give you list of all images. Now add it to seed file for model you want to add this images.
class Modelx
mount_uploader :avatar, AvatarUploader
end
So your seed file should have entries like.
Modelx.create([{:avatar_remote_url => image_url1}, {:avatar_remote_url => image_url2},.....])
You can set specific path and also create multiple dimension images using carrierwave.
REfrence url for carrierwave here.
I'm using an API to grab a thumbnail image. The API request automatically downloads the image. I'd like to store that image directly in my S3 bucket. It seems like overkill to use something like Carrierwave for this. How can I make the API call and save the image directly in S3?
Install the AWS S3 gem
sudo gem i aws-s3
and configure it by following the instructions here.
http://amazon.rubyforge.org/
then
S3Object.store('image.jpg', open('fileName.jpg'), 'bucketName')