Last active
August 29, 2015 13:57
-
-
Save cristiandley/9460398 to your computer and use it in GitHub Desktop.
meteor file reader/save
This file contains hidden or 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
/* | |
| | |
| | |
| THANKS Fats! he did the hard work | |
| | |
| | |
*/ | |
/* | |
| | |
| FORM | |
| you must have a main with {{yield}} | |
*/ | |
<template name="frm"> | |
<form role="form" enctype="multipart/form-data" action="uploadFile" method="post"> | |
<div class="form-group"> | |
<label for="exampleInputFile">File input</label> | |
<input type="file" id="file" name="file"> | |
</div> | |
<button type="submit" class="btn btn-default">Submit</button> | |
< /form> | |
</template> | |
/* | |
| | |
| ROUTES | |
| routes.map...etc | |
*/ | |
//load form | |
this.route('frm', { | |
path: '/frm' | |
}); | |
//server side file reader | |
this.route('subirArchivos', { | |
where: 'server', | |
method: 'POST', | |
path: '/subirArchivos', | |
action: function () { | |
var path = this.request.files.file.path; | |
var name = this.request.files.file.name; | |
if(Meteor.isServer){ | |
/* | |
| usuario_linux = your user | |
*/ | |
var fs = Npm.require('fs'); | |
var source = fs.createReadStream(path); | |
var dest = fs.createWriteStream('/home/usuario_linux/MeteorProject/public/' + name); | |
source.pipe(dest); | |
} | |
var name = this.request; | |
var parm = this.params; | |
this.response.writeHead(200, {'Content-Type': 'text/html'}); | |
this.response.end("filename: " + name + " PARM: " + parm); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would also like to know this please