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.

Reply

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)
}

Reply

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

I think that this episode can help you or at least give you some guidance!
https://gorails.com/episodes/trix-editor?autoplay=1

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

This is another video that covers what you need!
https://gorails.com/episodes/multiple-file-uploads-with-shrine?autoplay=1

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.

Reply

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
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.