In the controller action
change_img_params(params[:background_image])
def change_img_params(img)
begin
Base64.decode64(params[:user][img])
if params[:user][img]
params[:user][img] = file_decode(params[:user][img].split(',')[1],
params[:user][:screen_name] )
end
rescue Exception => e
params[:user][img]
end
end
Helpers
def file_decode(base, filename)
file = Tempfile.new([file_base_name(filename), file_extn_name(filename)])
file.binmode
file.write(Base64.decode64(base))
file.close
file
end
def file_base_name(file_name)
File.basename(file_name, file_extn_name(file_name))
end
def file_extn_name(file_name)
File.extname(file_name)
end