Skip to content

Instantly share code, notes, and snippets.

@emmanuelsw
Last active March 13, 2019 17:48
Show Gist options
  • Save emmanuelsw/ac9ff51a19893ede6db22d8410bdd46f to your computer and use it in GitHub Desktop.
Save emmanuelsw/ac9ff51a19893ede6db22d8410bdd46f to your computer and use it in GitHub Desktop.
Base64 to image and upload to AWS using ActiveStorage
def update_sign
sheet = Sheet.find(params[:id])
encoded_image = params[:sign].split(",")[1]
decoded_image = Base64.decode64(encoded_image)
filename = "firma-#{sheet.id}.svg"
File.open("#{Rails.root}/storage/#{filename}", "wb") { |f| f.write(decoded_image) }
sheet.image.attach(io: File.open("#{Rails.root}/storage/#{filename}"), filename: filename)
FileUtils.rm("#{Rails.root}/storage/#{filename}")
render json: rails_blob_path(sheet.image, disposition: "inline")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment