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

266
Views
Paperclip - Upload to different S3 URLs from Different models

I had a model from which I used paperclip and stored to S3.

In paperclip.rb

bucket_name = (Rails.env != 'production') ? "mcds_staging_fulltext" : 'mcds_fulltext'
Paperclip::Attachment.default_options.merge!({
  storage: :s3,
  s3_credentials: {
   bucket: bucket_name
},
url: "#{CUSTOMER}/static_cover_images/:style/:basename.:extension",
path: "#{CUSTOMER}/static_cover_images/:style/:basename.:extension"
})

model1.rb

  has_attached_file :cover_image, styles: { :original => ["100%"], :thumbnail => ["100*100", :png] }
  validates_attachment_content_type :cover_image, content_type: /\Aimage\/.*\Z/, message: 'Invalid Content Type. Please upload jpg/jpeg/png/gif'
  validates_attachment_size :cover_image, :in => 0.megabytes..5.megabytes, :message => 'must be smaller than 5 MB'

this works poperly and store my images in S3 in correct location.

Now I have another model from where I need to upload a paperclip attachment to a different S3 Location.

In model2.rb

 has_attached_file :xslt
 Paperclip::Attachment.default_options.merge!({url: "#{CUSTOMER}/xslts/:style/:basename.:extension"})
 validates_attachment_content_type :xslt, content_type: "application/xslt+xml", message: 'Invalid Content Type. Please upload jpg/jpeg/png/gif'
 validates_attachment_size :xslt, :in => 0.megabytes..5.megabytes, :message => 'must be smaller than 5 MB'

but this attachment still stores to my model1 S3 and not in the url specified in model2.

What am I doing wrong?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I completely removed paper_clip.rb file and added paper_clip configurations in therespective models.

model1:

has_attached_file :file1,
storage: :s3,
s3_credentials: {
 bucket: bucket_name
},
url: "#{CUSTOMER}/cover_images/:style/:basename.:extension",
path: "#{CUSTOMER}/cover_images/:style/:basename.:extension"

model2:

has_attached_file :file2,
storage: :s3,
s3_credentials: {
 bucket: bucket_name
},
url: "#{CUSTOMER}/file2_folder/:style/:basename.:extension",
path: "#{CUSTOMER}/file2_folder/:style/:basename.:extension"

this stores theattachment correctly in differen S3 folders.

about 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!