So I've been working and researching this all day but can't make it work. I'm working on my first meteor program, which takes input from a couple of csv files, runs some math, and return two new csv files. I figured I'd build out the parsing and returning of the csv files first since that seems like the most difficult part. I've managed to get the files in, but for the life of me can't get them back out. I'm sure it's something with the way I'm generating the file, but can't figure it out.
I realize there's a lot of code that doesn't work yet, but right now all I'm trying to do is pass a csv file through the vimeo field, parse it as an array, then re-download it as a csv to make sure the parsing/reparsing/downloading works. I finally managed to generate a downloadable file, but it's an empty html file. Any help world be appreciated.
Here's my current code:
HTML
<head>
<title>Josh's App</title>
</head>
<body>
<div class="container">
{{>csvTemplate}}
{{>downloadLinkTemplate}}
</div>
</body>
<template name="csvTemplate">
<form id="csv-upload">
<p><span class="label">Instructors File</span><br><input name="csvInstructors" type="file"></p>
<p><span class="label">Video List</span><br><input name="csvVideos" type="file"></p>
<p><span class="label">Vimeo Report</span><br><input name="csvVimeo" type="file"></p>
<input type="submit" value="Submit">
</form>
</template>
<template name="downloadLinkTemplate">
test
<a title="downloadTest" href="#" download="{{downloadUrl}}">Test Link</a>
</template>
Js1
if (Meteor.isClient) {
var fileTest;
Template.csvTemplate.events({
'submit form': function() {
event.preventDefault();
var csvInstructors;
var csvVideos;
var csvVimeo;
Papa.parse(event.target.csvInstructors.files[0], {
header: true,
dynamicTyping: true,
complete: function(results) {
csvInstructors = results;
csvPass()
}
});
Papa.parse(event.target.csvVideos.files[0], {
header: true,
dynamicTyping: true,
complete: function(results) {
csvVideos = results;
csvPass()
}
});
Papa.parse(event.target.csvVimeo.files[0], {
header: true,
dynamicTyping: true,
complete: function(results) {
csvVimeo = results;
fileTest = statReportGenerate(csvVimeo);
csvPass()
}
});
var csvPass = function(){ _.after(3, function() {
maths(csvInstructors, csvVideos, csvVimeo)
});
}
}})
Template.downloadLinkTemplate.helpers({
downloadUrl: function() {
console.log("below function", fileTest);
return statReports.find({_id: fileTest}).url()
}
})
}
if (Meteor.isServer) {
// This code only runs on the server
}
Js2
statReports = new FS.Collection("statReports", {
stores: [new FS.Store.GridFS("statReports", {path: "/reports/statReports"})]
});
paymentReports = new FS.Collection("paymentReports", {
stores: [new FS.Store.GridFS("paymentReports", {path: "/reports/paymentReports"})]
});
if (Meteor.isClient) {
statReportGenerate = function (statData) {
console.log("wtf", statData.data);
var omg = Papa.unparse(statData.data,{
header: true
});
var blob = new Blob([omg], {type: "text/csv;charset=utf-8"});
console.log("blob", blob);
return statReports.insert(blob)._id;
};
}