All files / exp/app/controller/common common.js

14.29% Statements 2/14
0% Branches 0/4
0% Functions 0/1
14.29% Lines 2/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40    3x                               3x                                          
'use strict'
 
const config = require('../../../config/env')
 
/**
 * @api {post} common/uploadFileLocal 上传文件到本地
 * @apiDescription 作者:samy
 *
 * @apiGroup common
 * @apiName uploadFileLocal
 * @apiSampleRequest common/uploadFileLocal
 * @apiPermission user
 *
 * @apiParam {Binnary} file 待上传文件的路径
 *
 * @apiUse Header
 * @apiUse Response
 */
exports.uploadFileLocal = async(req, res, next) => {
  let body = req.body
  console.log('-----body---->', body);
  console.log('-----req.files---->', req.files);
  try {
    let msg
    if (!req.file) {
      msg = '文件不能为空'
    }
    if (msg) {
      return res.resMid.resBody(res, 422, msg)
    }
    let resData = {
      filePath: req.files.path,
      url: `${config.host}${req.files.filename}`,
    }
    console.log('-----resData---->', resData);
    res.resMid.resBody(res, '', '上传成功', resData)// 返回文件名
  } catch (err) {
    res.throw(err)
  }
}