Created
August 7, 2013 07:32
-
-
Save baya/6171988 to your computer and use it in GitHub Desktop.
upload image to a file server
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 UploadBase64Image < Dun::Activity | |
data_reader :file_data, :as, :file_name | |
set :server_address, 'http://xx.xx.xx.xx' | |
set :client, RestClient | |
def initialize(data) | |
super | |
default :as, 'image' | |
default :file_name, SecureRandom.urlsafe_base64 | |
end | |
def call | |
client.post "#{server_address}/#{store_dir}/#{file_name}", file: file | |
end | |
private | |
def store_dir | |
"fchk/#{as}" | |
end | |
def file | |
get_or_set :file do | |
tempfile = Tempfile.new('fileupload') | |
tempfile.binmode | |
tempfile.write(Base64.decode64 file_data) | |
File.new(tempfile.path, 'rb') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment