Skip to content
Browse files

Adding simple example without progress

  • Loading branch information...
1 parent 2650ad5 commit f09eb6d28c1a9db03e059adb0748ba273cf5198a @phstc committed Jun 23, 2012
View
2 .gitignore
@@ -1,3 +1,3 @@
node_modules/
-examples/uploads
+examples/*/uploads
View
2 examples/app.coffee → examples/progress/app.coffee
@@ -1,6 +1,6 @@
app = require 'http'
fs = require 'fs'
-uploadProgress = require '../lib/node-upload-progress'
+uploadProgress = require '../../lib/node-upload-progress'
uploadHandler = new uploadProgress.UploadHandler
uploadHandler.configure ->
View
2 examples/app.js → examples/progress/app.js
@@ -5,7 +5,7 @@
fs = require('fs');
- uploadProgress = require('../lib/node-upload-progress');
+ uploadProgress = require('../../lib/node-upload-progress');
uploadHandler = new uploadProgress.UploadHandler;
View
0 examples/index.html → examples/progress/index.html
File renamed without changes.
View
20 examples/simple/app.coffee
@@ -0,0 +1,20 @@
+app = require 'http'
+fs = require 'fs'
+uploadProgress = require '../../lib/node-upload-progress'
+uploadHandler = new uploadProgress.UploadHandler
+
+uploadHandler.configure ->
+ this.uploadDir = "#{__dirname}/uploads"
+
+app.createServer((req, res) ->
+ if req.url == '/upload'
+ uploadHandler.upload req, res
+ else
+ fs.readFile "#{__dirname}/index.html", (err, data) ->
+ res.writeHead 200, {'Content-Type': 'text/html'}
+ res.write data.toString()
+ res.end()
+).listen(8080)
+
+console.log('Server running at http://localhost:8080/');
+
View
32 examples/simple/app.js
@@ -0,0 +1,32 @@
+(function() {
+ var app, fs, uploadHandler, uploadProgress;
+
+ app = require('http');
+
+ fs = require('fs');
+
+ uploadProgress = require('../../lib/node-upload-progress');
+
+ uploadHandler = new uploadProgress.UploadHandler;
+
+ uploadHandler.configure(function() {
+ return this.uploadDir = "" + __dirname + "/uploads";
+ });
+
+ app.createServer(function(req, res) {
+ if (req.url === '/upload') {
+ return uploadHandler.upload(req, res);
+ } else {
+ return fs.readFile("" + __dirname + "/index.html", function(err, data) {
+ res.writeHead(200, {
+ 'Content-Type': 'text/html'
+ });
+ res.write(data.toString());
+ return res.end();
+ });
+ }
+ }).listen(8080);
+
+ console.log('Server running at http://localhost:8080/');
+
+}).call(this);
View
20 examples/simple/index.html
@@ -0,0 +1,20 @@
+<html lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Test Upload</title>
+ <meta name="author" content="Pablo Cantero <pablo@pablocantero.com>">
+ <!-- Date: 2012-06-12 -->
+</head>
+<body>
+ <h1>Super Upload</h1>
+ <form action="/upload" enctype="multipart/form-data" method="post" id="form_upload">
+ <p>
+ <label>File</label><br/>
+ <input type="file" name="upload" id="upload">
+ </p>
+ <p>
+ <input type="submit" value="Upload">
+ </p>
+ </form>
+</body>
+</html>
View
3 lib/node-upload-progress.coffee
@@ -36,8 +36,9 @@ class UploadHandler
upload: (req, res) ->
query = url.parse(req.url, true).query
form = new formidable.IncomingForm()
+
@uploads.add query['X-Progress-ID']
-
+
form.parse req, (err, fields, files) =>
@uploads.remove query['X-Progress-ID']
res.writeHead 200, 'Content-type': 'text/plain'
View
5 test/unit/uploads_test.coffee
@@ -17,6 +17,11 @@ describe 'Uploads', ->
it 'should add and get a new upload', ->
$.uploads.add 1, $.upload
$.uploads.get(1).should.equal $.upload
+
+ it 'should add undefined', ->
+ # undefined uuid occurs when X-Progress-ID is not passed in the querystring
+ upload = $.uploads.add
+ should.exist upload
describe 'get', ->
it 'should return nil if the upload does not exist', ->

0 comments on commit f09eb6d

Please sign in to comment.
Something went wrong with that request. Please try again.