文件上传不适用于 localhost express 服务器

File upload not working on localhost express server

我正在尝试实施 ng file upload in a node app I'm running on localhost. I'm going off the demo here 但是当我更改要下载的目录时

file.upload = Upload.upload({
                url: 'uploadImages',
                data: {file: file}
            });

我遇到了 404:

angular.js:10765 POST http://localhost:8888/uploadImages/ 404 (Not Found)

我需要为该目录​​设置快速路由吗?我已经尝试过了,但它也不适用于

app.post('/uploadImages', cors(corsOptions), function(req, res){
    res.sendfile('./uploadImages')
});

不太确定从这里到哪里去。

是的,您需要像 Node Express 服务器一样设置 Web 服务器来接受 POST 请求。我过去这样做的方法是使用 multer,一种用于处理多部分上传的 Express 中间件。

示例

var express = require('express')
var multer = require('multer')

var app = express();

var upload = multer({
    dest: 'uploadImages/'
});

app.post('/uploadImages', upload.any(), function (req, res, next) {
  // req.files is the file uploaded, which multer will write to
  // the dest folder for you. req.body will contain the text fields,
  // if there were any.

  res.json(req.files.file);
});