rails-activestorage

Rails ActiveStorage: how to avoid one redirect for each image?

对着背影说爱祢 提交于 2019-12-22 17:44:09
问题 If you use ActiveStorage and you have a page with N images you get N additional requests to your Rails app (i.e. N redirects). That means wasting a lot of server resources if you have tens of images on a page. I know that the redirect is useful for signed URLs. However I wonder why Rails does not precompute the final signed URL and embed that into the HTML page... In this way we could keep the advantages of signed URLs / protected files, without making N additional calls to the Rails server.

How can I access an ActiveStorage object via URL in a test environment?

两盒软妹~` 提交于 2019-12-22 11:37:24
问题 Given a model that has an ActiveStorage attachment class MyObject has_one_attached :avatar end In a dev environment I am able to retrive the avatar as a StringIO object. obj = MyObject.new( { valid params } ) file = File.open( Rails.root.join( "spec/support/images/test_image.jpg" )) obj.avatar.attach( io: file, filename: "test_image.jpg" ) obj.save version = obj.avatar.variant( resize: '200x200>').processed version_url = Rails.application.routes.url_helpers.url_for( version ) download = open

Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated

China☆狼群 提交于 2019-12-22 10:57:19
问题 My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files . For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download. I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine. All environments use the config.active_storage.service = :local config/storage.yml local: service: Disk root: <%= Rails.root.join(

ActiveStorage to upload large base64 encoded string?

社会主义新天地 提交于 2019-12-22 07:00:04
问题 If I have an image that was edited/generated using JavaScript on the client (for example, a cropped photo or the result of a canvas drawing), is there a way to upload it using ActiveStorage? It would typically be a large string containing "<img src='data:image/jpeg;base64,...=='>" that is stored in a JavaScript variable, not a file. 回答1: As far as I know, Active Storage has currently no native support for that. Maybe this Rails issue has further information helpful to you. We have implemented

Rails Read csv file data with active storage

◇◆丶佛笑我妖孽 提交于 2019-12-22 03:59:11
问题 I have this class and I am using active storage class MaterialsUpload < ApplicationRecord has_one_attached :csv_file end This is the attachment #<ActiveStorage::Attached::One:0x007ff1f0be9e90 @dependent=:purge_later, @name="csv_file", @record= #<MaterialsUpload:0x007ff1f0c604f0 id: 3, success: 0, errors_list: [], total: 0, created_at: Mon, 12 Feb 2018 14:43:35 UTC +00:00, updated_at: Mon, 12 Feb 2018 14:43:35 UTC +00:00>> Is there a way I can read the data so I can do something like this

Active Storage with Amazon S3 not saving with filename specified but using file key instead

↘锁芯ラ 提交于 2019-12-21 20:54:18
问题 I am having an issue with Active Storage. When I upload to Amazon S3, instead of saving the file inside the bucket with the original name like myfile.zip it is saving it as the key which is associated with that file. So in Cyberduck I am seeing something like this: 5YE1aJQuFYyWNr6BSHxhQ48t . Without any file extension. I am not sure if there is some setting in Rails 5 or whether it is within Amazon S3 but I have spent hours Googling around to figure out why this is happening. Any pointers

How is the checksum calculated in the blobs table for rails ActiveStorage

自闭症网瘾萝莉.ら 提交于 2019-12-20 05:31:47
问题 Does anyone know how the checksum field in active_storage_blobs is calculated when using ActiveStorage on rails 5.2+? For bonus points, does anyone know how I can get it to use an md5 checksum that would match the one from the md5 CLI command? 回答1: Lets Break It Down I know i'm a bit late to the party, but this is more for those that come across this in a search for answers. So here it is.. Background: Rails introduced loads of new features in version 5.2, one of which was ActiveStorage . The

How is the checksum calculated in the blobs table for rails ActiveStorage

家住魔仙堡 提交于 2019-12-20 05:31:07
问题 Does anyone know how the checksum field in active_storage_blobs is calculated when using ActiveStorage on rails 5.2+? For bonus points, does anyone know how I can get it to use an md5 checksum that would match the one from the md5 CLI command? 回答1: Lets Break It Down I know i'm a bit late to the party, but this is more for those that come across this in a search for answers. So here it is.. Background: Rails introduced loads of new features in version 5.2, one of which was ActiveStorage . The

How to compress images before uploading to the cloud using ActiveStorage

只愿长相守 提交于 2019-12-18 08:49:37
问题 To save space in the cloud how would you go about resizing and compressing an image preupload using activestorage? 回答1: I tested this code below in development on local storage and it works, but anyway gives some problems that I will explain next. On create this seems to work fine, even if I suppose there should be a cleaner way to do so. class User < ApplicationRecord has_one_attached :avatar before_save :resize_avatar_image def resize_avatar_image filename = avatar.filename.to_s puts

“Request has expired” when using S3 with Active Storage

大城市里の小女人 提交于 2019-12-14 03:49:04
问题 I'm using ActiveStorage for the first time. Everything works fine in development but in production (Heroku) my images disappear without a reason. They were showing ok the first time, but now no image is displayed. In the console I can see this error: GET https://XXX.s3.amazonaws.com/variants/Q7MZrLyoKKmQFFwMMw9tQhPW/XXX 403 (Forbidden) If I try to visit that URL directly I get an XML <Error> <Code>AccessDenied</Code> <Message>Request has expired</Message> <X-Amz-Expires>300</X-Amz-Expires>