Reputation: 233
I am new to Meteor and web development in general, what I would like to achieve for my meteor web-app is the following:
All the information I found regarding this either deprecated, referring to collectionFS, or too specific/for a niche problem.This has proven more complicated than the issue appears to be!
What i would be looking for is either a tutorial-like guide explaining how to do so or some code snippets that would help get set-up for achieving the mentioned functionality.
EDIT
I have managed to upload files using the package tomi:meteor-upload .
This then creates a /.uploads
folder where my files are uploaded to.
When I try to download them from the client however using <a href="/.uploads/myfilename" download target="_blank">Download</a>
, I get that the files downloaded are damaged!
I also tried by uploading them to a /public
folder than the /.uploads
folder, but still having the same issue.
This is seen here, but no solution has been found, even if I chmod 777 my files manually I get the problem!
Thanks!
Upvotes: 0
Views: 1261
Reputation: 333
You can try busboy https://github.com/mscdex/busboy :
this.route('/upload', {
where: 'server',
method: 'POST',
name:'upload',
onBeforeAction: (function (req, res, next) {
//busboy code here
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function(data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function(fieldname, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
busboy.on('finish', function() {
console.log('Done parsing form!');
res.writeHead(303, { Connection: 'close', Location: '/' });
res.end();
next();
});
req.pipe(busboy);
});
you can use file.pipe(fs.createWriteStream(saveTo));
and the saveTo is the path you where upload, example: C:/media/
, and try to create ang Path of the link example: localhost:80/media/image-here.png
use method to store these link in your database, you can use APACHE for File hosting.
Upvotes: 0