【发布时间】:2018-05-25 09:40:54
【问题描述】:
我正在尝试创建一个处理文件上传的 Azure 函数。我尝试了不同的选项(尝试直接从请求中读取或使用强大的)。
对于这两种情况,执行函数时都会出现以下错误。
Exception while executing function: Functions.UploadFile. mscorlib: TypeError: req.on is not a function
at IncomingForm.parse (D:\home\site\wwwroot\node_modules\formidable\lib\incoming_form.js:117:6)
at module.exports (D:\home\site\wwwroot\UploadFile\index.js:5:10)
at D:\Program Files (x86)\SiteExtensions\Functions\1.0.11702\bin\azurefunctions\functions.js:106:24.
功能代码如下
var formidable = require("formidable");
module.exports = function (context, request) {
context.log('JavaScript HTTP trigger function processed a request.');
var form = new formidable.IncomingForm();
form.parse(request, function (err, fields, files) {
context.res = { body : "uploaded"};
});
context.done();
};
感谢任何帮助。
【问题讨论】:
-
你可以试试类似:
const buffers = []; request.on('data', (data) => { buffers.push(data); }); request.on('end', () => { context.res = { body : "uploaded"}; context.done(); }); -
感谢您的建议。我收到与此代码相同的错误消息。在 Azure 框架中,请求对象是否可能没有实现正确的接口集?
-
您能否尝试记录
request对象,看看它是否与express.js或其他一些框架具有相同的接口? -
当我执行 context.log(request) 时,我得到的只是在日志中请求 [object Object]。有没有其他方法可以找到接口?
-
你可以
JSON.stringify()它或util.inspect()它。
标签: node.js azure azure-functions serverless