Permalink
Browse files

Update code/application/requestHandlers.js

  • Loading branch information...
1 parent 080b6d5 commit 8fee5116505cafe7fc154ac86360dd97b0cb46df @heaventear committed Nov 11, 2012
Showing with 8 additions and 12 deletions.
  1. +8 −12 code/application/requestHandlers.js
View
20 code/application/requestHandlers.js
@@ -32,18 +32,14 @@ function upload(response, request) {
form.parse(request, function(error, fields, files) {
console.log("parsing done");
- /* Possible error on Windows systems:
- tried to rename to an already existing file */
- fs.rename(files.upload.path, "/tmp/test.png", function(err) {
- if (err) {
- fs.unlink("/tmp/test.png");
- fs.rename(files.upload.path, "/tmp/test.png");
- }
- });
- response.writeHead(200, {"Content-Type": "text/html"});
- response.write("received image:<br/>");
- response.write("<img src='/show' />");
- response.end();
+ fs.createReadStream(files.upload.path).
+ pipe(fs.createWriteStream('/tmp/test.jpg').on('close', function(){
+ response.writeHead(200, {"Content-Type": "text/html"});
+ response.write("received image:<br/>");
+ response.write("<img src='/show' />");
+ response.end();
+ }));
+
});
}

0 comments on commit 8fee511

Please sign in to comment.