Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created December 16, 2011 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloberg/1486200 to your computer and use it in GitHub Desktop.
Save mloberg/1486200 to your computer and use it in GitHub Desktop.
qq.FileUploader Ruby
directory = './tmp/'
# ajax upload
if params[:qqfile].class == String
name = params[:qqfile]
string_io = request.body
data_bytes = string_io.read
path = File.join(directory, name)
File.open(path, "w") do |f|
f.write(data_bytes)
end
# regular upload
else
name = params[:qqfile][:filename]
path = File.join(directory, name)
File.open(path, "wb") do |f|
f.write(params[:qqfile][:tempfile].read)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment