Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.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中的上载?_Node.js_Electron_Multer - Fatal编程技术网

Node.js 如何在服务器批准后才接受multer中的上载?

Node.js 如何在服务器批准后才接受multer中的上载?,node.js,electron,multer,Node.js,Electron,Multer,我正在编写一个应用程序,它使用electron、node和multer接受从客户端到服务器的上传。 我想做的是只允许上传后,服务器已接受它。也许是某种提示。我将如何在JS中进行 虽然我提到了穆特,但我想它不会在这件事中起到很大作用。Rn,我的上传功能是这样运行的 var upload = multer({ storage: storage, }) app.post('/uploadfile', upload.single('single'), (req, res, next) => {

我正在编写一个应用程序,它使用electron、node和multer接受从客户端到服务器的上传。 我想做的是只允许上传后,服务器已接受它。也许是某种提示。我将如何在JS中进行

虽然我提到了穆特,但我想它不会在这件事中起到很大作用。Rn,我的上传功能是这样运行的

var upload = multer({ storage: storage, })

app.post('/uploadfile', upload.single('single'), (req, res, next) => {
    const file = req.file
    if (!file) {
      const error = new Error('Please upload a file')
      error.httpStatusCode = 400
      return next(error)
    }
      res.send(file)
})

当请求到来时,我想我必须使用其他提示验证的东西,而不是运行“upload.single”,然后运行实际的上传功能。但我很无知。非常感谢您的帮助。

将上传过程与身份验证分开。对用户进行身份验证,然后允许用户上载文件。将上载过程与身份验证分开。对用户进行身份验证,然后允许用户上载文件。