All threads / File uploads in Rails with Shrine Discussion

Ask A Question

Notifications

You’re not receiving notifications from this thread.

File uploads in Rails with Shrine Discussion

has anyone used Shrine and Backblaze B2 storage?

Reply

Can Shrine make files secure? Ideally, selecting which file attachments are secure and which are public should be possible. Currently hard to do with ActiveStorage as you have to select it for all the attachments. Which is quite Basecamp centric in it's thinking.

yes it can

I have mine setup this way

Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: "#{ENV["CREDENTIALS_ENV"]}/cache", **s3_options),
store: Shrine::Storage::S3.new(prefix: "#{ENV["CREDENTIALS_ENV"]}/store", **s3_options),
public_store: Shrine::Storage::S3.new(public: true, upload_options: { cache_control: "max-age=15552000" }, prefix: "#{ENV["CREDENTIALS_ENV"]}/public", **s3_options)
}

you should use a gem like lockbox (https://github.com/ankane/lockbox) if you want to encrypt your files. It even has instructions for working with Shrine if you look at the docs.

Reply

What’s the story with Shrine if an application is also using Action Text?

Reply

Thank you for making these videos! They've been helpful. But what if the photos (multiple) are being added as a nested attribute on another model's create action? I've had so much trouble understanding this😫

Reply

Guys, I'm trying to get shrine to work with my rails api but I can't figure out what I'm messing.

I'm able to upload the file but the image_data that is return doesn't go to my image_data column. It gives me a JSON Parse error 783. What I'm supposed to do? Store the image_data as a string (eg. "{\"id\":\"89966472375f0c62dd2f8404da931d84.jpg\",\"storage\":\"cache\",\"metadata\"...) or what?

I'm using a SPA as front-end. The problem is when I try to use the uploaded file into the model that have the atacched file metadata.

Ok, I changed PG column to json and now it works. Some tutorials I read stated to use string and not json but it works fine, so I guess that's it.

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 43,185+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.