0

I am trying to get rename and onFileUploadComplete to call their console log but it never does, it does however call my console in post, which is giving me a string of a file that is not there.

var express = require("express");
var multer = require("multer");
var Excel = require("exceljs");
var router = express.Router();
var fs = require('fs');

var doneUpload = false;
var displayResults = [];
var Excelfile;


router.use(multer({ dest: "./uploads/",
 rename: function (fieldname, filename) {
   console.log("Filename: "+filename);
  return new Date().getTime() + filename;
  },
  onFileUploadComplete: function (file) {
      saveFile = file;
      console.log("onFileUploadComplete ");
    doneUpload = true;
  }
}).single("excelFile"));

router.get("/", function(req, res){
  res.sendFile(__dirname + "/index.html");
});

router.post("/api/fileupload" ,function(req, res){
    Excelfile = req.file.path;
    console.log(typeof Excelfile);

    res.render("results", {
      displayResults: displayResults
    });
});
module.exports = router;

Thanks in advance.My ultimate goal is to have a file I can pass into excel JS and currently it is saying the file is not in the correct string format. I suspect because the file is being renamed to the long string of numbers "uploads/7ab48192a1c548a3dce3b9d74cad6592" which is never pointing to an actual file. I further suspect this because I ran typeof and it is does give me back a string - just not one pointing to a file, especially if onFileUploadComplete never gets fired telling me the file is uploaded?

tcoulson
  • 602
  • 3
  • 10
  • 37
  • did you succeed upload your file using multer? if you want a callback have you tried busboy as your requirement? – Gujarat Santana Aug 28 '15 at 14:46
  • I have not been able to get busboy to work with my setup currently. I am not sure what code to put in, there is a lack of really good examples on the web for using busboy with multer. – tcoulson Aug 31 '15 at 14:16
  • You do not need multer when using busboy, you can implment it directly to your code using busboy withou busboy. source from my experience – Gujarat Santana Sep 01 '15 at 08:59
  • Could you provide more details? I really don't know what busboy even does. It says "A streaming parser for HTML form data for node.js". What I need is to use a file chooser online to download a file, read it, and get rid of said file. I can do that with multer, I did not think busboy would give me that ability. – tcoulson Sep 02 '15 at 15:55

1 Answers1

1

The usage for Multer has changed. These callbacks would not work. Have a look at these links:

https://github.com/expressjs/multer
multer callbacks not working ?

Gaurav Gupta
  • 1,929
  • 4
  • 21
  • 40