Permalink
Browse files

Removed File logging

  • Loading branch information...
1 parent 8e917f0 commit 3d5a7875aac6e4044ec367b540cde3f49d7933a6 root committed Apr 9, 2012
Showing with 64 additions and 6 deletions.
  1. +2 −3 app.js
  2. +4 −1 config.js
  3. +2 −0 package.json
  4. +56 −2 routes/index.js
View
5 app.js
@@ -3,11 +3,10 @@
*/
require("./logger").init();
var logger = require('./logger').logger;
-logger.use(require('devnull/transports/stream'), {
+/*logger.use(require('devnull/transports/stream'), {
stream: require('fs').createWriteStream('loggers.log')
-});
+});*/
-logger.log("test");
var express = require('express')
, routes = require('./routes')
View
@@ -20,4 +20,7 @@ module.exports = {
// If you need help finding a bug just turn on debugging.
debug: true // true or false
-};
+
+ // Posts the image to a webserver
+ //post: "http://localhost/photos"
+};
View
@@ -12,5 +12,7 @@
, "formidable": ">= 0.0.1"
, "progress-bar": ">= 0.0.1"
, "devnull": ">= 0.0.1"
+ , "multiparter": ">= 0.0.1"
+ , "mime": ">= 0.0.1"
}
}
View
@@ -8,7 +8,11 @@ var qs = require("querystring"),
util = require("util"),
exec = require('child_process').exec,
child,
- path = require("path");
+ path = require("path"),
+ multiparter = require("multiparter"),
+ http = require("http"),
+ mime = require("mime"),
+ url = require("url");
function md5HexDigest(data)
{
@@ -43,8 +47,8 @@ exports.upload = function(req, res) {
console.error("error here")
})
.on("end", function () {
+ var file = folder+req.files.FILENAME.filename.substr(0, req.files.FILENAME.filename.length -4);
if(config.cards[obj.macaddress].command) {
- var file = folder+req.files.FILENAME.filename.substr(0, req.files.FILENAME.filename.length -4);
console.log(file);
var command = util.format(config.cards[obj.macaddress].command, path.normalize(file));
@@ -57,6 +61,56 @@ exports.upload = function(req, res) {
}
});
}
+
+ if(config.post) {
+ var settings = url.parse(config.post);
+ var request = new multiparter.request(http, {
+ host: settings.hostname,
+ port: settings.post,
+ path: settings.pathname,
+ method: "POST"
+ });
+
+
+ request.addStream(
+'file',
+path.basename(file),
+mime.lookup(file),
+fs.statSync(file).size,
+fs.createReadStream(file));
+
+ request.send(function(error, response) {
+ if (error) {
+ console.log(error);
+ }
+
+ var data = "";
+
+ response.setEncoding("utf8");
+
+ response.on("data", function(chunk) {
+ data += chunk;
+ });
+
+ response.on("end", function() {
+ console.log("Data: " + data);
+ });
+
+ response.on("error", function(error) {
+ console.log(error);
+ });
+ });
+/* fs.readFile(file, function (err, data) {
+ console.log(err);
+ console.log(data);
+ request.post({uri: "http://localhost:3000/photos"
+ , body: data
+ , form: true
+ }, function (error, response, body) {
+ console.log(error);
+ });
+ });*/
+ }
console.log(req.socket._idleStart.getTime());
console.log(new Date().getTime());
console.log("\nFinished Upload successfully.");

0 comments on commit 3d5a787

Please sign in to comment.