Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

amazon s3 - Not able to migrate this type of link to activestorage

I am following this example to carry on a silent migration from paperclip to active storage, in one piece of the code theres a call:

 ActiveRecord::Base.transaction do  
  blob = ActiveStorage::Blob.create_after_upload!(  
    io: open(URI.parse(URI.escape("https://s3-#{ENV['AWS_AS_S3_REGION']}.amazonaws.com/#{ENV['AWS_AS_S3_BUCKET']}/" + key(picture_type.to_s)))),    
    filename: send("#{picture_type}_file_name"),    
    content_type: send("#{picture_type}_content_type")  
  ) 

   blob.attachments.create( 
    name: picture_type.to_s,    
    record_type: self.class.name,   
    record_id: id   
  ) 
end 

It worked out well for pretty much all paperclip attachments I had but just one type of URL is coming up with some errors, here an example link (not a real one, I changed the bucket name and the region):

URI.open(URI.parse(URI.decode( "https://s3-region.amazonaws.com/bucketname/photos/images/000/005/218/original/Desayuno_Barcelo%CC%81_Granada_Congress.jpg?1608043256"  )))

this gives me the error:

URI::InvalidURIError (URI must be ascii only "https://s3-region.amazonaws.com/bucketname/photos/images/000/005/218/original/Desayuno_Barcelou0301_Granada_Congress.jpg?1608043256")

the decode doesn't seem to bring up the exact character since I get that

question from:https://stackoverflow.com/questions/65922768/not-able-to-migrate-this-type-of-link-to-activestorage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...