Created
November 10, 2012 21:55
-
-
Save jbuchacher/4052670 to your computer and use it in GitHub Desktop.
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
// client/upload.js | |
$('#upload-file').on('submit', function(e) { | |
// the event | |
console.log(e); | |
// This could support multiple files, just proof of concept | |
var imageFile = e.target.elements[0].files[0]; | |
console.log('Image Name: ' + imageFile.name); | |
// Use FileReader | |
var fileReader = new FileReader(); | |
fileReader.onloadend = (function(result) { | |
return exports.send(result, "nothing", function(success) { | |
console.log("uploaded by client."); | |
}); | |
}); | |
fileReader.readAsDataURL(imageFile); | |
}); | |
exports.send = function(image, options, cb) { | |
return ss.rpc('upload.uploadImage', image, options, cb); | |
}; | |
// server/upload.js | |
var fs = require('fs'); | |
exports.actions = function(req, res, ss) { | |
req.use('session'); | |
return { | |
uploadImage: function(image, options, callback) { | |
console.log("Uploading image " + image); | |
var imagePath = "./temp.png"; | |
fs.writeFile(imagePath, image, function(err) { | |
console.log(err); | |
return res(false); | |
}); | |
return res(true); | |
} | |
}; | |
}; | |
// html | |
<form action="#" id="upload-file" enctype="multipart/form-data"> | |
<input type="file" id="fileToUpload"> | |
<input type="submit" value="Upload"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment