Skip to content

Image attachment with activestorage - #775

Merged
eitoball merged 4 commits into
masterfrom
image-attachment-with-activestorage
Feb 23, 2021
Merged

eitoball merged 4 commits into
masterfrom
image-attachment-with-activestorage

Conversation

@eitoball

@eitoball eitoball commented Feb 17, 2021 •

Copy link
Copy Markdown
Member

This PR tries to use Active Storage to attach image to device story comments like in #765.

For more information about Active Storage, see https://guides.rubyonrails.org/v5.2/active_storage_overview.html#attaching-file-io-objects.

I am not sure if Cloudinary is required. If required, we still can integrate like in https://cloudinary.com/documentation/rails_activestorage

@eitoball eitoball self-assigned this Feb 17, 2021
@eitoball
eitoball force-pushed the image-attachment-with-activestorage branch 2 times, most recently from 2d80b98 to 015be0a Compare February 17, 2021 16:00
@eitoball eitoball mentioned this pull request Feb 17, 2021
Comment thread Gemfile Outdated
gem 'fog-aws', '~> 2.0.0'
gem 'formatted-dates'
gem 'has_scope', '~> 0.7.1'
gem 'image_processing'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure if imagemagick is installed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need an .ebextention to cover that

@eitoball
eitoball marked this pull request as ready for review February 17, 2021 16:10
@matschaffer

Copy link
Copy Markdown
Contributor

Hm... I was thinking cloudinary would be good to help with porn-prevention in image uploads, but looks like https://cloudinary.com/blog/how_to_automate_image_moderation_with_amazon_rekognition says we'd need to set up AWS rekognition for that.

In which case maybe we could just use activestorage.

@eitoball is there something in here that'll put the images on s3? We can't just have them go to disk since the app autoscales.

@matschaffer

Copy link
Copy Markdown
Contributor

@eitoball

Copy link
Copy Markdown
Member Author

is there something in here that'll put the images on s3? We can't just have them go to disk since the app autoscales.

@matschaffer Not yet. I wasn't sure what service we're gonna use. Can I use the same access key ID and secret access key as those to store bGegie logs files? Or, different ID and key?

@matschaffer

Copy link
Copy Markdown
Contributor

Same should be fine. The ec2 instance has an IAM profile for that bucket. Maybe put images in another prefix just so they don’t get mixed with uploads.

@eitoball
eitoball force-pushed the image-attachment-with-activestorage branch 3 times, most recently from 6fb4cb3 to 68061dd Compare February 18, 2021 22:59

@matschaffer matschaffer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising so far. Is it ready for dev? Not sure how automagic the s3 part is so let me know when you're ready for deployment.

errors.add(:image, 'is too large (maximum is 10MB)')
end

VALID_IMAGE_TYPES = [Mime[:bmp], Mime[:jpeg], Mime[:gif], Mime[:png]].freeze

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure hope no-one will really upload a bmp, but good that we support it 😆

@eitoball

Copy link
Copy Markdown
Member Author

Is it ready for dev? Not sure how automagic the s3 part is so let me know when you're ready for deployment.

@matschaffer Sort of. We need to create a S3 bucket to store image and set the bucket name in environment variable DEVICE_STORY_COMMENT_IMAGES_BUCKET.

If it is okay, I would like to deploy to dev environment by myself. If so, I would like to set up environment variables in Beanstalk.

@matschaffer

matschaffer commented Feb 19, 2021 via email

Copy link
Copy Markdown
Contributor

@eitoball
eitoball force-pushed the image-attachment-with-activestorage branch 2 times, most recently from 2556881 to 00c79f3 Compare February 19, 2021 21:20
@eitoball
eitoball force-pushed the image-attachment-with-activestorage branch from 00c79f3 to 759618a Compare February 20, 2021 05:22
@eitoball
eitoball force-pushed the image-attachment-with-activestorage branch from 759618a to 37c0794 Compare February 20, 2021 05:25

@matschaffer matschaffer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @eitoball ! Thanks 🧡

@eitoball
eitoball merged commit 860d784 into master Feb 23, 2021
@eitoball
eitoball deleted the image-attachment-with-activestorage branch February 23, 2021 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants