Skip to content

Instantly share code, notes, and snippets.

@cristiandley
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cristiandley/9460398 to your computer and use it in GitHub Desktop.
Save cristiandley/9460398 to your computer and use it in GitHub Desktop.
meteor file reader/save
/*
|
|
| 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);
}
});
@boustanihani
Copy link

Could you please also include the sample code needed for streaming a file back to the client ?

@gibex
Copy link

gibex commented Jan 19, 2015

If you don;t mind asking, how did you solve "this.request.files" not defined ? Do you have a nodejs library included in project?

THanks

@daslicht
Copy link

I would also like to know this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment