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 | 5x 5x | '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(ctx, next) => {
let body = ctx.request.body
console.log('-----body---->', body);
console.log('-----req.files---->', ctx.req.files);
try {
let msg
if (!ctx.req.file) {
msg = '文件不能为空'
}
if (msg) {
return ctx.resMid.resBody(ctx, 422, msg)
}
let resData = {
filePath: ctx.req.files.path,
url: `${config.host}${ctx.req.files.filename}`,
}
console.log('-----resData---->', resData);
ctx.resMid.resBody(ctx, '', '上传成功', resData)// 返回文件名
} catch (err) {
ctx.throw(err)
}
} |