Created
January 4, 2011 08:29
-
-
Save josevalim/764536 to your computer and use it in GitHub Desktop.
Improve file uploads with Zombie
This file contains 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
// Improvements to file uploads with Zombie. | |
// | |
// Just start the Sinatra server below and run this file with node. | |
// Depending on the server used with Sinatra, it will fail upfront or forward | |
// a bad request to the app. The source code in zombie is in the link below | |
// (you will need Zombie from git, you can check it out and use `npm link`): | |
// | |
// https://github.com/assaf/zombie/blob/master/src/zombie/history.coffee#L93 | |
// | |
var zombie = require("zombie"); | |
var browser = new zombie.Browser; | |
browser.visit("http://localhost:4567/upload", function (err) { | |
browser.attach("File", __filename) | |
browser.pressButton("Upload", function(err){ | |
console.log(browser.html()); | |
}); | |
}); |
This file contains 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
require "rubygems" | |
require "sinatra" | |
helpers do | |
include Rack::Utils | |
alias_method :h, :escape_html | |
end | |
get "/upload" do | |
<<-HTML | |
<html> | |
<head> | |
<title>Upload</title> | |
</head> | |
<body> | |
<form enctype="multipart/form-data" action="/upload" method="post"> | |
<label>File<input type="file" name="form[file]"></label> | |
<input type="submit" value="Upload"> | |
</form> | |
</body> | |
</html> | |
HTML | |
end | |
post "/upload" do | |
h(params.inspect).tap do | |
puts request.env.inspect | |
puts request.env["rack.request.form_input"].read.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! I got an error testing this client.js with a node.js server.
app.js