Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Multer Filename回调中的错误参数是什么?_Node.js_File_Express_Error Handling_Multer - Fatal编程技术网

Node.js Multer Filename回调中的错误参数是什么?

Node.js Multer Filename回调中的错误参数是什么?,node.js,file,express,error-handling,multer,Node.js,File,Express,Error Handling,Multer,我使用Multer从ExpressAPI请求中获取文件,我想知道文件名回调中错误值的用途是什么。这是我的密码: const multerFile = multer({ storage: multer.diskStorage({ destination: "uploads/", filename: (req, file, callback) => { callback(ERROR HERE WHAT IS THIS FOR?, "

我使用Multer从ExpressAPI请求中获取文件,我想知道文件名回调中错误值的用途是什么。这是我的密码:

const multerFile = multer({
  storage: multer.diskStorage({
    destination: "uploads/",
    filename: (req, file, callback) => {
      callback(ERROR HERE WHAT IS THIS FOR?, "fileNameHere`); 
    },
  }),
});

在Node中,异步回调通常的构造方式是第一个参数是错误,或者第二个参数是成功值。例如,您经常会看到这样的模式:

callSomeAPI((error, result) => {
  if (error) {
    // There was an error, do something with it
    handleError(error);
  } else {
    // Success
    handleResults(result);
  }
});
这个
filename
回调也在做同样的事情。如果实现某些自定义逻辑并希望指示进程失败,请将包含原因的第一个参数传递给回调:

callback('Desired filename contains invalid characters');
否则,将第一个参数保留为null:

callback(null, 'fileNameHere');