0

我目前正在使用文件上传功能。

使用以下示例: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);
};

会不会是最新的 Node 版本不支持?

我收到以下错误消息:

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}
4

1 回答 1

0

mime.lookup 重命名为 mime.getType 见https://www.npmjs.com/package/mime

你包括什么版本的file-api?正是出于这个原因,node-sdk-example 包含 git://github.com/voodoohop/file-api.git。请参阅https://github.com/node-file-api/file-api/issues/4

于 2018-06-24T17:58:08.483 回答