Formidable和maxFileSize,崩溃或不崩溃?

时间:2018-04-01 13:01:49

标签: javascript firebase nodes formidable

我使用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.(但此刻线总是包括在内。)

1 个答案:

答案 0 :(得分:0)

嗯,发生了什么事。我为那些有同样问题的人写了一个答案,但它刚刚消失了。

如果您遇到此问题,请在此处查看其他方法:

Firebase cloud function for file upload