1

My DBs of production and development are somewhat in sync, so development can read images from production paths (S3).

The problem is when I delete, update or create records on development, it affects the S3 image.

I don't want this behavior to happen on development but it should happen on production.

Is there an option to turn paperclip into readonly mode? I still want to see the images from S3 (and not 404 images).

I saw the :preserve_files option which is good to protect delete. Is there an option to protect overwrite / disable upload?

elado
  • 8,510
  • 9
  • 51
  • 60
  • A little late, but an excellent question. Is it possible to make a read-only set of creds using Identity and Access Management (IAM)? See: http://stackoverflow.com/questions/1856988/how-to-restrict-amazon-s3-api-access –  Oct 24 '13 at 00:18

2 Answers2

1

Well, patchy, ugly and unsafe for future versions, but does the job for the meantime.

config/initializers/paperclip.rb

if Rails.env.development?
  module Paperclip
    class Attachment
      def assign uploaded_file
      end

      def save
      end

      def clear(*)
      end

      def destroy
      end

      private
      def post_process(*)
      end

      def post_process_styles(*)
      end

      def post_process_style(*)
      end

      def queue_some_for_delete(*)
      end

      def queue_all_for_delete
      end

      def after_flush_writes
      end
    end
  end
end
elado
  • 8,510
  • 9
  • 51
  • 60
0

Assuming you need to use production data in development, I think it would make a lot more sense to create a "User Policy" where a user can only read certain S3 resources. Then change your environment variables accordingly https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-policies-s3.html

Then, you can handle errors in development (S3 client should fail if you try to update with read only privileges). This ensures you can't touch anything in production

For example (pseudocode),

if Rails.env.development?
  // do not update
else
  Model.attachment.assign()
end
codster
  • 71
  • 4