Skip to content

Instantly share code, notes, and snippets.

@baya
Created August 7, 2013 07:32
Show Gist options
  • Save baya/6171988 to your computer and use it in GitHub Desktop.
Save baya/6171988 to your computer and use it in GitHub Desktop.
upload image to a file server
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