Skip to content

Commit

Permalink
Merge pull request manuelkiessling#10 from Aaronontheweb/patch-1
Browse files Browse the repository at this point in the history
Added a fs.unlinkSync call to the requestHandler.js file - on Windows if you try to rename a new file onto one that already exists the file system spits an error back at you. This approach removes the file before the rename is ever attempted.
  • Loading branch information
manuelkiessling committed Dec 9, 2011
2 parents d5214b9 + ef805f7 commit 0e0f750
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/application/requestHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ function upload(response, request) {
console.log("about to parse");
form.parse(request, function(error, fields, files) {
console.log("parsing done");

/*
* Some systems [Windows] raise an error when you attempt to rename new file into one that already exists.
* This call deletes the previous .PNG image prior to renaming the new one in its place.
*/
fs.unlinkSync("/tmp/test.png"); .
fs.renameSync(files.upload.path, "/tmp/test.png");
response.writeHead(200, {"Content-Type": "text/html"});
response.write("received image:<br/>");
Expand Down

0 comments on commit 0e0f750

Please sign in to comment.