rails-activestorage

How to add a custom service to ActiveStorage

吃可爱长大的小学妹 提交于 2021-01-21 04:35:46
问题 I want to add a custom service to ActiveStorage because I want to overwrite the url method of the ActiveStorage::Service::S3Service service so I can use a CloudFront CDN in front of my S3 bucket. I think I will not need the presigned_url params, I will just need the key, because the CloudFront instance will have full read access to the S3 bucket. 回答1: Add a class in the ActiveStorage::Service namespace that subclasses ActiveStorage::Service::S3Service . Override the methods you want to

How to add a custom service to ActiveStorage

半世苍凉 提交于 2021-01-21 04:33:45
问题 I want to add a custom service to ActiveStorage because I want to overwrite the url method of the ActiveStorage::Service::S3Service service so I can use a CloudFront CDN in front of my S3 bucket. I think I will not need the presigned_url params, I will just need the key, because the CloudFront instance will have full read access to the S3 bucket. 回答1: Add a class in the ActiveStorage::Service namespace that subclasses ActiveStorage::Service::S3Service . Override the methods you want to

Rails: How to disable ActiveStorage Analyzers and Previewers

白昼怎懂夜的黑 提交于 2020-12-05 11:50:45
问题 I have a Rails 5.2.3 app using ActiveStorage. By default, ActiveStorage would run some background jobs to extract metadata from attached files, and/or create thumbnail images for previews. I don't want that. I don't need any metadata, nor do I need any thumbnails. So how can I disable these background jobs? According to the official Rails guide, I've set config.active_storage.analyzers = [] config.active_storage.previewers = [] in /config/application.rb . However, looks like it doesn't help.

Configuring ActiveStorage to use S3 with IAM role

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-24 09:17:26
问题 I'm trying to configure ActiveStorage to use S3 bucket as a storage backend however I don't want to pass any of access_key_id , secret_access_key , region . Instead, I'd like to use previously defined IAM role. Such configuration is mentioned here. It reads (I've added bold): If you want to use environment variables, standard SDK configuration files, profiles, IAM instance profiles or task roles, you can omit the access_key_id, secret_access_key, and region keys in the example above. The

Rails API ActiveStorage: Get Public URL to display image from AWS S3 Bucket?

我只是一个虾纸丫 提交于 2020-08-08 06:45:26
问题 I have a Rails 5.2 API set up and have followed the documentation on how to attach images to a model object - that's all working fine. The problem I'm having is I want to return in a JSON object the attachment's public URL so that I can use that URL as the source in an <img src... in my React front end. Is there a way to return the actual URL from the AWS S3 bucket, where the image would show up if clicked on? Right now, I've tried rails_blob_path , service_url , and I do get URLs in return,

Callback for Active Storage file upload

我的梦境 提交于 2020-07-09 03:08:06
问题 Is there a callback for active storage files on a model after_update or after_save is getting called when a field on the model is changed. However when you update (or rather upload a new file) no callback seems to be called? context: class Person < ApplicationRecord #name :string has_one_attached :id_document after_update :call_some_service def call_some_service #do something end end When a new id_document is uploaded after_update is not called however when the name of the person is changed

Update Active Storage attachment filename

余生长醉 提交于 2020-06-26 12:40:30
问题 I want to know how to update the filename of an Active Storage attachment. Here's what I'm trying now: 2.5.1 :052 > attachment.filename => #<ActiveStorage::Filename:0x00007fb2926cf6a0 @filename="example.pdf"> # at this point the filename is example.pdf 2.5.1 :053 > attachment.update!(filename: 'foo.pdf') (0.2ms) BEGIN Patient Load (0.5ms) SELECT "patients".* FROM "patients" WHERE "patients"."deleted_at" IS NULL AND "patients"."id" = $1 LIMIT $2 [["id", 40861], ["LIMIT", 1]] (0.2ms) COMMIT =>

Rails ActiveStorage scope for when file is attached

做~自己de王妃 提交于 2020-05-27 04:43:41
问题 When using ActiveStorage, how do you create a scope for when files are attached. For example: class Check < ActiveRecord::Base has_one_attached :image end I want something like Check.has_attached_image to return only records where there is an existing attached image. I know that ActiveStorage provides a with_attached_image scope. But that doesn't seem to be working: irb(main):009:0> Check.with_attached_image.to_sql => "SELECT \"checks\".* FROM \"checks\"" 回答1: Main purpose of the scope with

Rails 5.2 ActiveStorage with UUIDs on Postgresql

女生的网名这么多〃 提交于 2020-05-25 07:46:05
问题 We have our app using uuids are primary keys, on a Postgresql Database. (Standard setup described here). We integrated ActiveStorage following the process described here. A standard setup using rails active_storage:install and migrated using rails db:migrate . We have a model & corresponding controller as follows: # Model class Message < ApplicationRecord has_one_attached :image def filename image&.attachment&.blob&.filename end end # Controller class MessagesController <