Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Default S3 permissions trigger Aws::S3::Errors::InvalidArgument from AWS SDK #1974

Closed
camhine opened this issue Aug 27, 2015 · 12 comments
Closed

Comments

@camhine
Copy link

camhine commented Aug 27, 2015

The default s3_permissions (:public_read) cause an Aws::S3::Errors::InvalidArgument exception when trying to save a model with an attached file.

Somewhere along the line support for :public_read has been dropped for 'public-read'.

Setting s3_permissions: 'public-read' in the config fixes the problem - 'public-read' should probably be the default going forward.

@jyurek
Copy link

jyurek commented Aug 28, 2015

What version of Paperclip and the aws-sdk are you using? I've just pulled in a PR that allows for aws-sdk v2 compatibility, and which also changes the default when using aws-sdk v2 to "public-read".

@camhine
Copy link
Author

camhine commented Aug 30, 2015

I'm using paperclip from git, revision: ece46f4

aws-sdk is version 2.0.48

I've just noticed that aws-sdk-v1 (1.65.0) is also in my Gemfile.lock. Maybe the version 2 default is being clobbered by the version 1 default?

Broken paperclip initializer:

Paperclip::Attachment.default_options.merge!(
  bucket: ENV['AWS_BUCKET'],
    # s3_permissions: 'public-read',
  s3_region: ENV['AWS_REGION'],
  storage: :s3
)

Uncommenting that s3_permissions fixes the issue.

Backtrace:

Aws::S3::Errors::InvalidArgument - :
  aws-sdk-core (2.0.48) lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
  aws-sdk-core (2.0.48) lib/aws-sdk-core/plugins/s3_sse_cpk.rb:18:in `call'
  aws-sdk-core (2.0.48) lib/seahorse/client/plugins/param_conversion.rb:22:in `call'
  aws-sdk-core (2.0.48) lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
  aws-sdk-core (2.0.48) lib/seahorse/client/plugins/response_target.rb:18:in `call'
  aws-sdk-core (2.0.48) lib/seahorse/client/request.rb:70:in `send_request'
  aws-sdk-core (2.0.48) lib/seahorse/client/base.rb:216:in `block (2 levels) in define_operation_methods'
  aws-sdk-resources (2.0.48) lib/aws-sdk-resources/services/s3/file_uploader.rb:42:in `block in put_object'
  aws-sdk-resources (2.0.48) lib/aws-sdk-resources/services/s3/file_uploader.rb:49:in `open_file'
  aws-sdk-resources (2.0.48) lib/aws-sdk-resources/services/s3/file_uploader.rb:41:in `put_object'
  aws-sdk-resources (2.0.48) lib/aws-sdk-resources/services/s3/file_uploader.rb:34:in `upload'
  aws-sdk-resources (2.0.48) lib/aws-sdk-resources/services/s3/object.rb:102:in `upload_file'
  /home/vagrant/.bundler/ruby/2.2.0/paperclip-ece46f46e9b9/lib/paperclip/storage/s3.rb:405:in `block in flush_writes'
  /home/vagrant/.bundler/ruby/2.2.0/paperclip-ece46f46e9b9/lib/paperclip/storage/s3.rb:373:in `flush_writes'
  /home/vagrant/.bundler/ruby/2.2.0/paperclip-ece46f46e9b9/lib/paperclip/attachment.rb:238:in `save'
  /home/vagrant/.bundler/ruby/2.2.0/paperclip-ece46f46e9b9/lib/paperclip/has_attached_file.rb:92:in `block in add_active_record_callbacks'
  activesupport (4.2.3) lib/active_support/callbacks.rb:444:in `block in make_lambda'
  activesupport (4.2.3) lib/active_support/callbacks.rb:226:in `block in halting_and_conditional'
  activesupport (4.2.3) lib/active_support/callbacks.rb:504:in `block in call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
  activerecord (4.2.3) lib/active_record/callbacks.rb:302:in `create_or_update'
  activerecord (4.2.3) lib/active_record/persistence.rb:142:in `save!'
  activerecord (4.2.3) lib/active_record/validations.rb:43:in `save!'
  activerecord (4.2.3) lib/active_record/attribute_methods/dirty.rb:29:in `save!'
  activerecord (4.2.3) lib/active_record/transactions.rb:291:in `block in save!'
  activerecord (4.2.3) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
  activerecord (4.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
  activerecord (4.2.3) lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
  activerecord (4.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
  activerecord (4.2.3) lib/active_record/transactions.rb:220:in `transaction'
  activerecord (4.2.3) lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
  activerecord (4.2.3) lib/active_record/transactions.rb:291:in `save!'
  app/jobs/pathway_application/process_profile_image_job.rb:8:in `perform'
  activejob (4.2.3) lib/active_job/execution.rb:32:in `block in perform_now'
  activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
  activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:496:in `block (2 levels) in around'
  activesupport (4.2.3) lib/active_support/callbacks.rb:341:in `block (2 levels) in simple'
  activejob (4.2.3) lib/active_job/logging.rb:23:in `block (4 levels) in <module:Logging>'
  activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument'
  activejob (4.2.3) lib/active_job/logging.rb:22:in `block (3 levels) in <module:Logging>'
  activejob (4.2.3) lib/active_job/logging.rb:43:in `block in tag_logger'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  activejob (4.2.3) lib/active_job/logging.rb:43:in `tag_logger'
  activejob (4.2.3) lib/active_job/logging.rb:19:in `block (2 levels) in <module:Logging>'
  activesupport (4.2.3) lib/active_support/callbacks.rb:439:in `block in make_lambda'
  activesupport (4.2.3) lib/active_support/callbacks.rb:340:in `block in simple'
  activesupport (4.2.3) lib/active_support/callbacks.rb:495:in `block in around'
  activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
  activejob (4.2.3) lib/active_job/execution.rb:31:in `perform_now'
  activejob (4.2.3) lib/active_job/execution.rb:21:in `execute'
  activejob (4.2.3) lib/active_job/queue_adapters/inline_adapter.rb:14:in `enqueue'
  activejob (4.2.3) lib/active_job/enqueuing.rb:71:in `block in enqueue'
  activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
  activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:496:in `block (2 levels) in around'
  activesupport (4.2.3) lib/active_support/callbacks.rb:341:in `block (2 levels) in simple'
  activejob (4.2.3) lib/active_job/logging.rb:14:in `block (3 levels) in <module:Logging>'
  activejob (4.2.3) lib/active_job/logging.rb:43:in `block in tag_logger'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  activejob (4.2.3) lib/active_job/logging.rb:43:in `tag_logger'
  activejob (4.2.3) lib/active_job/logging.rb:13:in `block (2 levels) in <module:Logging>'
  activesupport (4.2.3) lib/active_support/callbacks.rb:439:in `block in make_lambda'
  activesupport (4.2.3) lib/active_support/callbacks.rb:340:in `block in simple'
  activesupport (4.2.3) lib/active_support/callbacks.rb:495:in `block in around'
  activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
  activejob (4.2.3) lib/active_job/enqueuing.rb:67:in `enqueue'
  activejob (4.2.3) lib/active_job/enqueuing.rb:17:in `perform_later'
  app/controllers/pathway_application/profile_images_controller.rb:9:in `create'
  actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.2.3) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
  activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
  actionpack (4.2.3) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.3) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.3) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.3) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.3) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
  actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:45:in `serve'
  actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  activerecord (4.2.3) lib/active_record/migration.rb:377:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  airbrake (4.3.1) lib/airbrake/rails/middleware.rb:13:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  airbrake (4.3.1) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (4.3.1) lib/airbrake/user_informer.rb:12:in `call'
  rack-heartbeat (1.0.1) lib/rack/heartbeat.rb:27:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  puma (2.13.4) lib/puma/configuration.rb:78:in `call'
  puma (2.13.4) lib/puma/server.rb:541:in `handle_request'
  puma (2.13.4) lib/puma/server.rb:388:in `process_client'
  puma (2.13.4) lib/puma/server.rb:270:in `block in run'
  puma (2.13.4) lib/puma/thread_pool.rb:106:in `block in spawn_thread'

betesh added a commit to betesh/paperclip that referenced this issue Sep 2, 2015
@betesh
Copy link
Contributor

betesh commented Sep 2, 2015

It was a bug in #1903. I just opened a PR.

@tute
Copy link
Contributor

tute commented Sep 9, 2015

Thanks! Fixed with that PR. 👍

@MarkMurphy
Copy link

@tute the readme should probably mention when upgrading from aws-sdk < 2 to 2.x that the paperclip configuration value for s3 permissions should be updated from :public_read to "public-read"

@tute
Copy link
Contributor

tute commented Nov 10, 2015

@tute the readme should probably mention when upgrading from aws-sdk < 2 to 2.x that the paperclip configuration value for s3 permissions should be updated from :public_read to "public-read"

Sure! Can you point at an error message, or commit by which this is necessary, so we refer to it in the commit message?

@MarkMurphy
Copy link

@tute Probably the one tagged with 4.3.1

I was upgrading to aws-sdk ~> 2 to hopefully solve an issue with aws-sdk 1.54 replacing original uploads with 0 kb files on reprocess (#1936).

Then got uninitialized constant Paperclip::Storage::S3::AWS using the latest 4.3.1

I found an issue stating that I needed to add s3_region to my paperclip initializer. So I did that and got the same error. Turns out I had to use the current master string from github to get things working which was when I came across #1974, I still had:

s3_permissions: {
   original: :public_read
}

which I had to update to:

s3_permissions: {
  original: "public-read"
}

@gurgelrenan
Copy link

Like @MarkMurphy suggested, is there any chance to update the Readme, informing this update?

@betesh
Copy link
Contributor

betesh commented Nov 25, 2015

@tute
Copy link
Contributor

tute commented Nov 25, 2015

Sure! If you send a PR I'll merge right away, otherwise I'll do probably next week.
Thanks!

@betesh
Copy link
Contributor

betesh commented Nov 25, 2015

The PR: #2064

@gurgelrenan
Copy link

Thanks @betesh nice job!

betesh added a commit to betesh/paperclip that referenced this issue Jan 20, 2016
betesh added a commit to betesh/paperclip that referenced this issue Feb 5, 2016
jthurn24 added a commit to jthurn24/ppclip-RoR that referenced this issue Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants