无法在API的邮递员中显示消息

时间:2020-10-13 14:44:45

标签: node.js api postman

我将邮递员用作api测试软件,但我无法使用此api在邮递员中获取任何消息

这是我的文件上传库:

const appConfig = require("../../config/appConfig");
const multer = require('multer');
const GridFsStorage = require('multer-gridfs-storage');
const path = require('path');
const crypto = require('crypto');


  // Create storage engine
  const storage = new GridFsStorage({
    url: appConfig.db.uri,
    file: (req, file) => {
      return new Promise((resolve, reject) => {
        crypto.randomBytes(16, (err, buf) => {
          if (err) {
            return reject(err);
          }
          const filename = buf.toString('hex') + path.extname(file.originalname);
          const fileInfo = {
            filename: filename,
            bucketName: 'uploads',
            originalFileName: file.originalname
          };
          global.uploadedFileInfo = fileInfo;
          resolve(fileInfo);
         
        });
      });
    }
  });

let upload = multer({ storage });

module.exports = { upload: upload };

这是我的控制器文件

let uploadFile = (req,res) => {
    return res.status(200).json(global.uploadFileInfo);
}

module.exports {
uploadFile :uploadFile 
}

enter image description here 这是我的路由器文件

app.post(`${baseUrl}/upload`, attachments.upload.single('file'), attachmentController.uploadFile);

0 个答案:

没有答案