Last active
December 1, 2020 00:10
-
-
Save szabcsee/8523329 to your computer and use it in GitHub Desktop.
Revisions
-
szabcsee revised this gist
Jan 29, 2014 . 2 changed files with 37 additions and 19 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ require 'sinatra' require 'json' require 'csv' # Serve data as JSON get '/hi/:name' do name = params[:name] content_type :json { :message => name }.to_json end # Serve data as CSV file get '/csv' do content_type 'application/csv' attachment "myfilename.csv" csv_string = CSV.generate do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end end # Upload form get '/upload' do erb :upload end # Handle POST-request (Receive and save the uploaded file and line by line load its content to an array.) post '/upload' do content = params['myfile'][:tempfile].read content_arr = [] content.each_line do |line| content_arr << line end puts content_arr return "The operation has been successful! The uploaded csv content is in an array." end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +0,0 @@ -
szabcsee renamed this gist
Jan 20, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
szabcsee renamed this gist
Jan 20, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
szabcsee renamed this gist
Jan 20, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
szabcsee created this gist
Jan 20, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ require 'sinatra' require 'json' require 'csv' get '/hi/:name' do name = params[:name] content_type :json { :message => name }.to_json end get '/csv' do content_type 'application/csv' attachment "myfilename.csv" csv_string = CSV.generate do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end end