+ io = File.open(user.image.path)
+ filename = user.image.original_filename
+ content_type = if user.image.content_type.nil?
+ MimeMagic.by_magic(io)&.type
+ else
+ user.image.content_type
+ end
+
+ user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)