我使用Formidable上传Node.js文件。我有一个最大文件大小,有时它按预期工作,有时Firebase本地服务器说执行崩溃。我误解了怎么做吗?或者这只是说“Firebase beta崩溃”?
我尝试在“错误”事件中处理最大文件大小,如下所示:
form.on("error", function(err) {
let errStr = err.toString();
console.info("------------- In on error", errStr);
console.info("In on error, errStr", errStr.length, errStr);
let errInfo;
if (errStr.search("maxFileSize") !== -1) {
errInfo = "Max file size is currently "+form.maxFileSize+" bytes.";
}
res.writeHead(400, {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST,GET",
'content-type': 'text/json'
});
console.info("In on error, form.parse ERROR, my headers sent");
let ret = { error:errStr };
if (errInfo) ret.errInfo = errInfo;
console.info("In on error, ret", JSON.stringify(ret));
res.end(JSON.stringify(ret));
console.info("In on error, form.parse ERROR, my res sent");
});
从此我可以在本地Firebase服务器控制台中获得这样的输出:
info: User function triggered, starting execution
info: uploadaudio start ================================================================
info: ------------- In on error Error: maxFileSize exceeded, received 2113285 bytes of file data
info: Execution took 265 ms, finished with status: 'crash'
info: In on error, errStr 64 Error: maxFileSize exceeded, received 2113285 bytes of file data
In on error, form.parse ERROR, my headers sent
In on error, ret {"error":"Error: maxFileSize exceeded, received 2113285 bytes of file data","errInfo":"Max file size is currently 2097152 bytes."}
In on error, form.parse ERROR, my res sent
请注意“已完成状态:'崩溃'”的行。这是本地服务器写的东西,并且它不会一直出现在同一个地方。
当这行包含在日志中时,我回到浏览器500。否则我会回到400.(但此刻线总是包括在内。)
答案 0 :(得分:0)
如果您遇到此问题,请在此处查看其他方法: