Last active
March 13, 2019 17:48
-
-
Save emmanuelsw/ac9ff51a19893ede6db22d8410bdd46f to your computer and use it in GitHub Desktop.
Base64 to image and upload to AWS using ActiveStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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