Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Paperclip: elija entre guardar archivos localmente o S3 en tiempo de ejecución

Estoy usando Paperclip para guardar archivos. He configurado con éxito para que Paperclip guarde archivos directamente en Amazon S3. Pero en algunas situaciones, necesito que los archivos solo se guarden localmente. Mi pregunta es: ¿Cómo puedo hacer esto.

Aquí está mi ejemplo de configuración de Paperclip:

 Paperclip.interpolates(:upload_url) { |attachment, style| "#{ENV.fetch('UPLOAD_PROTOCOL', 'http')}://#{ENV.fetch('UPLOAD_DOMAIN', 'localhost:3000')}/uploads/:class/:attachment/:id_:style.:extension" } Paperclip::Attachment.default_options.merge!( storage: :s3, s3_region: ENV['CEPH_REGION'], s3_protocol: 'http', s3_host_name: ENV['CEPH_HOST_NAME'], s3_credentials: { access_key_id: ENV['CEPH_ACCESS_KEY_ID'], secret_access_key: ENV['CEPH_SECRET_KEY'], }, s3_options: { endpoint: ENV['CEPH_END_POINT'], force_path_style: true }, s3_permissions: 'public-read', bucket: ENV['CEPH_BUCKET'], url: ':s3_path_url', path: ':class/:id/:basename.:extension', use_timestamp: false ) module Paperclip def self.string_to_io(options) data = StringIO.new(options[:data]) data.class.class_eval{ attr_accessor :original_filename } data.original_filename = options[:original_file_name] data end end
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Podrías usar una lambda. Como se muestra aquí. https://github.com/thoughtbot/paperclip#configuración-dinámica

se vería algo como esto.

 class YOURMODEL < ActiveRecord::Base has_attached_file :FILE, storage: lambda { |attachment| (attachment.instance.use_s3? ? :s3 : :filesystem) } end

¿Entonces tendrías que agregar un método use_s3? a su modelo para verificar si desea almacenar el archivo localmente o con s3.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!