Skip to content

Instantly share code, notes, and snippets.

@jbuchacher
Created November 10, 2012 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbuchacher/4052670 to your computer and use it in GitHub Desktop.
Save jbuchacher/4052670 to your computer and use it in GitHub Desktop.
// 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