Search code examples
circuit-sdk

Circuit SDK File Upload Example not working on node 8


I am currently playing with the file upload functionality.

Using the example from: https://github.com/circuit/node-sdk-example/blob/master/index.js

var FileAPI = require('file-api');
var File = FileAPI.File;

//*********************************************************************
//* getFiles -- helper
//*********************************************************************
this.getFiles = function(path) {
    var files = [];
    var fileNames = fs.readdirSync(path);
    fileNames.forEach(function (element) {
        var file = new File(path + element);
        files.push(file);
    });
    logger.debug('[APP]: getFiles' + files);
    return files;
};


//*********************************************************************
//* Circuit - Post Logs
//*********************************************************************
this.postLog = function () {
    logger.info('[APP]: Log Message will be posted');

    //Get post content from File
    var text = fs.readFileSync(config.log_message,'utf8')
    logger.info('[APP]: Log Message extracted :', text);

    //Get files from folder
    var files = self.getFiles(config.log_folder);

    var message = {
        content: text,
        attachments: [files]
    };
    return client.addTextItem(config.conversationID, message);
};

Could it be that it is not supported in the latest Node version?

I get the following error message:

TypeError: mime.lookup is not a function\n    
at new File (/GIT/logToCircuit/node_modules/File/File.js:37:35)\n    
at /GIT/logToCircuit/app.js:109:24\n    
at Array.forEach (native)\n    
at LogToCircuit.getFiles (/GIT/logToCircuit/app.js:108:19)\n    
at LogToCircuit.postLog (/GIT/logToCircuit/app.js:128:26)\n    
at /GIT/logToCircuit/app.js:84:18\n    
at /GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:18119:25\n    
at Array.forEach (native)\n    
at BaseEventTarget.dispatch (/GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:18117:34)\n    
at /GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:49132:27","time":"2018-06-24T11:52:28.631Z","v":0}

Solution

  • mime.lookup was renamed to mime.getType see https://www.npmjs.com/package/mime.

    What version of file-api are you including? The node-sdk-example includes git://github.com/voodoohop/file-api.git for exactly this reason. See https://github.com/node-file-api/file-api/issues/4.