rails-activestorage

Cannot load Rails.config.active_storage.service

不羁岁月 提交于 2021-02-18 20:49:19
问题 I'm setting up a new rails 5.2 app utilising Active Storage and using AWS for the hosting of images in production. However, I'm having an issue with the app reading the credentials: 2018-07-06T08:11:52.625415+00:00 app[web.1]: ! Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: Cannot load `Rails.config.active_storage.service`: 2018-07-06T08:11:52.625432+00:00 app[web.1]: missing credentials, provide credentials with one of the following options: 2018-07-06T08:11:52

Organise Active Storage files for use in other systems?

感情迁移 提交于 2021-02-17 05:58:04
问题 Active Storage stores uploads in a file structure like so: This is great if the rails app is the only software that needs to use these files. But what if the app simply serves as a means to upload the images to S3 so that some other (completely separate) service can consume them? The problem being, other developers wouldn't be able to make any sense of the directory and files, since they're labelled in a way rails can understand, but which a human cannot (e.g. what does folder named "O2" mean

ActiveStorage & S3: Make files public

限于喜欢 提交于 2021-02-07 10:33:22
问题 In my rails application, some images should be public and others should be private . (I don't mind to have all of them public). Currently, when calling ActiveStorage's service_url (when using s3 ), a new presigned url is being generated. I totally understand this, but it's not what I want to do. Right now, generating the presigned url is taking too much time: Example: Getting 10 records: ActiveRecord: 52.3ms Generating the JSON: 1,790ms If we dig deeper, we see the following: S3 Storage (23

Active Storage public_url not returning key/filename.extension

十年热恋 提交于 2021-02-05 12:04:49
问题 The public option is added to Active Storage in this PR: https://github.com/rails/rails/pull/36729 In it he clearly says: "In the public bucket, the directory structure is /[key]/[filename]" Which makes sense and is exactly what I want. I want to be able (for example) to email the link to someone and allow them to download the file. So I need the filename.extension. But when I spin up a Rails 6.1 app the uploads to my bucket do not have the filename after them. The files do appear in my

How to preview pdf using active storage and poppler?

柔情痞子 提交于 2021-01-29 09:24:08
问题 I'm trying to display a preview of the uploaded pdf in my application but all I get so far is a broken image. I have installed the poppler gem as suggested in the active storage presentation for preview. Then i tried different ways but all are returning a broken image. <%= link_to bank.rib, rails_blob_path(bank.rib, disposition: "preview") %> or <%= image_tag bank.rib %> or where ' rib ' being the attached file ( has_one ) of the model BankAccount (here bank = BankAccount.find(id) ) bank.rib

active storage - prevent download - open file in browser when possible

微笑、不失礼 提交于 2021-01-29 02:29:06
问题 I am using rails_blob_url(o.audio_file) but it is annoying since url doesn't open file in browser but downloads the file as an attachment (this is not a default browser behaviour for audio files). I want that browser opens the file however it wants. I do not want to force download file ... rails_blob_url(o.audio_file, disposition: :inline) Doesn't work. 回答1: In addition to using rails_blob_url(o.audio_file, disposition: :inline) you also have to allow the content type. Rails.application

Rails ActiveStorage Using Custom S3 API

做~自己de王妃 提交于 2021-01-28 11:04:57
问题 I want to use Rails ActiveStorage, but I am using non-AWS S3 API object storage. amazon: service: S3 access_key_id: "" secret_access_key: "" region: "" bucket: "" On the documentation, it says that we need the region, my S3 API has no region. Is the any way to use custom S3 API? 回答1: I solved it by using the endpoint key on the configuration file. It look like this. amazon: service: S3 access_key_id: "123" secret_access_key: "asd" endpoint: "http://192.168.1.201:30103" bucket: "test" Do not

Cannot find module '@rails/ujs' - Rails 6 Webpack App

被刻印的时光 ゝ 提交于 2021-01-28 01:43:00
问题 I have these errors in a Rails 6 app and all javascript is not working: ERROR in ./app/javascript/packs/application.js Module not found: Error: Can't resolve '@rails/activestorage' in '/Users/jrsahuquillo/Dropbox/myappname/app/javascript/packs' @ ./app/javascript/packs/application.js 9:0-31 ERROR in ./app/javascript/packs/application.js Module not found: Error: Can't resolve '@rails/ujs' in '/Users/jrsahuquillo/Dropbox/myappname/app/javascript/packs' @ ./app/javascript/packs/application.js 5

ActiveStorage::FileNotFoundError but the file actually exists

北城余情 提交于 2021-01-27 07:17:24
问题 I am working on this Rails 6.0.21 application (ruby 2.5.5) and using puma 3.12.2 as development web server and ActiveStorage with local disk service. Every now and then my application errors out with ActiveStorage::FileNotFoundError . The actual file exists on disk. The model responds properly to .attached?. Restarting puma solves the issue which then pops up again later apparently at random...some days more often than others. This is happening on Apache with mod_passenger in the same way. Am

How to add a custom service to ActiveStorage

徘徊边缘 提交于 2021-01-21 04:37:04
问题 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