Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.