Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:03:11+00:00 2026-06-05T10:03:11+00:00

I have a model with a avatar paperclip attach. It has now a plain

  • 0

I have a model with a avatar paperclip attach. It has now a plain standard path

has_attached_file :avatar,
  :path => "/:id-:style-:filename"

Which I need to move into an obfuscated one

has_attached_file :avatar,
  :path => "/:id-:hash.:extension"
  :hash_secret => 'asecuresecret'

Everything’s working fine with new images, but how do I migrate the existing files stored in S3 to the new path format, ie rename them?

I’m using paperclip 2.7 and Rails 3.2

Thanks !!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:03:13+00:00Added an answer on June 5, 2026 at 10:03 am

    This rake task should do the trick. I tried it with aws-sdk 1.5.2 and ruby 1.9.3p194.

    The new_key should map to your new paperclip path. Don’t forget to set :acl according to your needs.

    namespace :data do
      desc 'aws images migration'
      task :migrate_images do |t, args|
        s3 = AWS::S3.new(:access_key_id => 'XXX', :secret_access_key => 'XXX')
        bucket = s3.buckets['your-bucket-name']
        bucket.objects.each do |object|
          new_key = object.key.gsub(........)
          new_object = bucket.objects[new_key]
          object.copy_to new_object, {:acl => :public_read}
        end
      end
    end
    

    The original file should be deleted manually or using a similar task, once you are sure the new file is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model named Profile which: has_attached_file :avatar I'm validating it to only
I have model Foo which has field bar. The bar field should be unique,
I have the following in my user model attr_accessible :avatar, :email validates_presence_of :email has_attached_file
in Rails 2.3.6 I have a User model: class User < ActiveRecord::Base has_attached_file :avatar,
I have model Article it has field title with some text that may contain
I have installed the Paperclip plugin to attempt to upload an avatar for my
I have following model: class UserProfile(models.Model): User profile model, cintains a Foreign Key, which
I have model UserProfile with field avatar = models.ImageField(upload_to=upload_avatar) upload_avatar function names image file
my model: has_attached_file :avatar, :styles => { :thumb => 65x65> }, :storage => :s3,
I have my own User model in app engine, which should have a property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.