Created
January 27, 2015 07:35
-
-
Save Martin91/3a958394e84f82f2158f to your computer and use it in GitHub Desktop.
save base64 file as uploaded
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
| class XXXController < ApplicationController | |
| def create | |
| moment = Moment.new photo: preprocess_uploaded_photo | |
| # ... | |
| end | |
| def preprocess_uploaded_photo | |
| encoded_photo_data = params[:moment][:photo] | |
| image_data = Base64.decode64(encoded_photo_data['data:image/png;base64,'.length .. -1]) | |
| tempfile = Tempfile.new ['upload', 'png'] | |
| tempfile.binmode | |
| tempfile.write(image_data) | |
| ActionDispatch::Http::UploadedFile.new(tempfile: tempfile, | |
| filename: 'upload.png') | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment