Shrine upload_options for checksum_algorithm giving an error - ruby-on-rails

I'm new to S3 and Shrine, and I'm working with a Shrine uploader in Ruby on Rails to upload files to Amazon S3, which has been in place for a couple of years on this Rails app.
The thing I'm working on has a goal to have S3 generate a checksum when uploading files, and according to these docs for adding a "trailing checksum" the ChecksumAlgorithm needs to be used: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html
In the ruby SDK docs, it lists checksum_algorithm as a param.
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Object.html#put-instance_method
When I add the param in the Shrine uploader (plugin :upload_options, { checksum_algorithm: 'SHA256' }) and upload the file, I get the error ArgumentError: unexpected value at params[:checksum_algorithm] from aws-sdk-core/param_validator.rb:33:in 'validate!' https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb#L14.
I've tried different cases, with and without the dash, and anything else I can think of syntax-wise, but no luck.

It turns out I was using an older version of aws-sdk-s3 and updating the gem solved the problem. Thanks #Janko

Related

Upload system-generated file to S3 using ActiveStorage?

I have a need to upload a system-generated file to S3. I'm aware that I could use something like the AWS Ruby SDK for this. However, I'm already using ActiveStorage elsewhere in my application and it seems simpler, if possible, to use ActiveStorage for everything rather than ActiveStorage plus some other library.
Is this possible using ActiveStorage?
I was able to find the answer in this part of the documentation:
#message.image.attach(io: File.open('/path/to/file'), filename: 'file.pdf')

Rails carrierwave and cloudinary multiple file uploads

So I'm trying to get carrierwave to work with cloudinary for multiple file uploads but it keeps giving me this error that says:
undefined method `all_versions_processors' for Array
I followed the carrierwave documentation where I added a listing_images attribute to my Listings table which is of type json.
I also set the multiple to true option in the form file input.
And in my ListingsController I have specified as one of the permitted params the following:
listing_images: []
I'm pretty sure everything is configured properly but I can't figure out why this error is thrown. Any help would be greatly appreciated.
It's on the road-map to officially support multiple uploads with Carrierwave on Cloudinary's GEM. In the meantime, as a workaround, you can accomplish multiple uploads a bit differently. Here's a basic sample project that demonstrates it:
https://github.com/taragano/Cloudinary_multiple_uploads

Can I use zipline gem to download from s3 without model associations with paperclip or carrierwave

I want to allow my user to download a bundle of files that are stored on s3 using the zipline gem. The files are already hosted on an s3 server but they aren't there as part of a paperclip or carrierwave attachment in my app. Will I need to create some records in my database to sort of trick zipline into thinking they are paperclip attachments, or is there a way I can send the zip file without bothering with an attachment gem? At the moment, trying to download the files with zipline doesn't throw an error message at all. It just seems to skip right over and nothing downloads.
See the part of the zipline README where an enumerator gets used to include remote files into the ZIP. It uses absolute URLs, to generate those from your S3 objects you will need to use presigned URLs (which Zipline is going to pass on to Curb):
Aws::S3::Bucket.new(your_bucket_name).object(your_key).presigned_url(:get)

Paperclip: Validate/process attachment before upload

Paperclip offers nice validator methods like
validates :image, attachment_size: { in 0..2.megabytes }
My problem is that attachment files get uploaded to S3 even though the validators would add errors to the attachment hosting object. So if the image is too big it's getting uploaded and the ActiveRecord-Object is getting errors on it when validating. That's okay but for my situation it would be more clean to reject uploads that are too big.
Is there a way to tap into the process and prevent a file from being uploaded to S3 under certain conditions?
Currently my implementation cares for the errors and deletes the attachment afterwards if the hosting object is not valid.
The described situation refers to Rails 4.0 application using Ruby 2.0.
The described problem does not occur in more recent Paperclip versions (most recent version at the time I'm writing this: 4.2). Files won't be uploaded to S3 when validations have attached errors to the AR-Object then.

Paperclip upload to S3 is failing silently...help!

I have an application which uploads images to an S3 bucket using Paperclip. It's been working fine for months, but suddenly my files are not being uploaded to the S3 bucket. Unfortunately, I've been doing a refactoring in a number of unrelated areas, and it's possible that something I changed broke my upload.
I'm using paperclip 2.3.1.
That said, there are a number of confusing aspects to this and frankly I am at a loss. First, there are no errors in the log indicating that the upload failed. The paperclip attachment attributes are populated in the database. The application thinks the upload occurred successfully. But when I look in S3, the file is not there.
Second, I have an almost identical attachment on a different model, which uploads to the same S3 bucket successfully -- the code is almost identical, and there clearly cannot be a permissions issue.
I found references in several places that suggested removing the right_aws game and instead only having the aws_s3 gem...which I did...but to no avail. Moreover, I never saw the (5 for 4) error in my log regardless.
Does anyone have any suggestions on how I can further diagnose this? Are there any options in paperclip to increase the verbosity of logging?
Thanks!
I had this issue as well and the cause was that my :multipart => true key/value hadn't been nested correctly in the :html key of the form_for helper.
It turns out the app was using Paperclip 2.3.4 which introduced some S3 issues.
Upgrading to 2.3.5 solved the issue for me.

Resources