Skip to content

Instantly share code, notes, and snippets.

@digitalextremist
Last active December 16, 2015 08:19
Show Gist options
  • Save digitalextremist/5404953 to your computer and use it in GitHub Desktop.
Save digitalextremist/5404953 to your computer and use it in GitHub Desktop.
Breaking Request.params; unable to parse multipart POST
source "http://rubygems.org"
#de ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.2'
gem "rack", :github => 'digitalextremist/rack', :branch => 'master'
gem 'rack-contrib', '1.1.0'
gem 'rack-jsonp', "1.3.1"
gem 'rack-protection', "1.5.0"
gem 'rack-cache'
gem "mongo"
#de gem "mongrel"
gem "puma"
#de gem 'jruby-openssl'
gem 'reel', :github => 'digitalextremist/reel', :branch => 'master'
gem 'celluloid'
gem 'celluloid-io', "~> 0.13.1"
gem "octarine", :github => 'digitalextremist/octarine', :branch => 'master'
gem 'peach'
gem "erubis"
gem "sinatra", '1.3.5'
gem "sinatra-contrib", '1.3.1'
gem 'json'
gem "pony"
gem "therubyrhino"
gem "rqrcode"
gem "nokogiri", "~>1.5.5java"
gem "sanitize"
gem "geocoder", "1.1.6"
gem 'active_support', "3.0.0"
gem 'verbs'
gem 'pdfkit'
gem 'stemmify'
#de gem 'open-uri'
#de gem "gems/linguistics-1.0.9.gem" #de , :git => "https://github.com/ged/linguistics.git"
gem 'execjs'
gem 'jsmin'
gem 'uglifier'
gem "closure-compiler"
gem 'yuicompressor'
gem 'rainpress'
gem "phony", "1.9.0"
gem "RubySunrise"
gem 'timezone'
gem 'tzinfo'
#de gem 'gd2'
#de gem 'thumbnailer'
gem 'streamio-ffmpeg'
gem 'rvideo'
gem 'rmagick4j'
gem 'mime-types'
gem "password_strength"
gem "fb_graph"
gem "twilio-ruby"
gem "googlevoiceapi"
require 'rubygems'
require "bundler/setup"
MU_UPLOADS = "/mu/rack-reel/uploads/"
LIB_BASE = "/mu/tweaking/"
require ( REEL_LIB = "/mu/rack-reel/reel/lib/" ) + 'reel'
require LIB_BASE + 'rack/lib/rack'
require LIB_BASE + 'rack/lib/rack/request'
require LIB_BASE + 'rack/lib/rack/multipart'
require 'sinatra'
require "sinatra/multi_route"
require "sinatra/reloader"
require 'mongo'
require 'json'
use Rack::Reloader
class BinMode #de has no effect on outcome
def initialize(app)
@app = app
end
def call(env)
if !env['rack.input'].nil?
env['rack.input'].binmode
end
@app.call(env)
end
end
use BinMode
set :show_exceptions, true
set :raise_errors, true
set :server, :reel
set :bind, "0.0.0.0"
set :port, "88"
get '/', "/uploading" do
redirect '/uploader.html'
end
post "/uploading", "/" do
tmp_name = Time.now.to_i.to_s + "." + ( BSON::ObjectId.new.to_s ) + ".01E"
File.open( MU_UPLOADS + tmp_name + ".js", "w" ) do |f| f.write( JSON.pretty_generate( request.env ) ) end
if request.env.is_a?( Hash ) and request.env.has_key? "rack.input"
File.open( MU_UPLOADS + tmp_name, 'w') {|f| f.write( request.env['rack.input'].read ) }
_de "saved rack.input // " + tmp_name
end
puts "Show params //"
puts params
if params.has_key? "file"
File.open( MU_UPLOADS + params["file"][:filename], 'w') {|f| f.write( params["file"][:tempfile].read ) }
puts "saved file // " + "uploads/" + params["file"][:filename]
end
redirect "/" if !request.xhr?
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>test-reel; multipart parsing</title>
<style type="text/css">
body {
font-family: Helvetica, Verdana, Geneva, sans-serif;
background-color: #111;
font-size: 14px;
color: #eee;
padding: 25px;
}
b { color: #aaa; }
a { color: #f60; text-decoration: none; }
input[type='text'], textarea { padding: 3px; border: #444 solid 1px; background: #999; }
#form { position: absolute; top: 25px; right: 25px; }
#label { position: absolute; bottom: 25px; left: 25px; }
#label h3 { color: #444; }
input[type='submit'], input[type='button'] { font-weight: bold; color: #111; padding: 3px 15px; border: #f60 solid 1px; background: #f60; }
</style>
<!-- <script type="text/javascript" src="/uploader.js"></script> -->
</head>
<body>
<div id="container">
<input type="button" id="pickfiles" href="javascript:;" value="Select Files" />
<input type="button" id="uploadfiles" href="javascript:;" value="Upload Files" />
<br /><br />
<div id="filelist"></div>
</div>
<div id="label"><h3>multipart & standard POST testing</h3></div>
<div id="form">
<form action="/" method="post">
<input type="text" name="textfield" value="ipsum lorem" /><br />
<textarea name="textarea">ipsum lorem</textarea><br />
<input type="submit" />
</form>
</div>
<script type="text/javascript">
/*
// Custom example logic
function $(id) { return document.getElementById(id); }
var uploader = new plupload.Uploader({
runtimes : 'html5,flash',
browse_button : 'pickfiles',
container: 'container',
max_file_size: '1000mb',
url: '/uploading',
flash_swf_url: '/uploader.swf',
});
uploader.bind('FilesAdded', function(up, files) {
for (var i in files) {
$('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
}
uploader.start();
});
uploader.bind('UploadProgress', function(up, file) {
$(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
});
$('uploadfiles').onclick = function() {
uploader.start();
return false;
};
uploader.init();
*/
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment