当前位置:网站首页>Node -- egg implements the interface of uploading files
Node -- egg implements the interface of uploading files
2022-07-02 00:20:00 【A walking sheep】
1. To configure config > config.default.js
config.multipart = {
mode: 'file'
}
2. controller File creation fileController.js
const Controller = require('egg').Controller;
class FileController extends Controller{
async upload() {
const {
ctx } = this;
let res = await ctx.service.fileService.upload()
ctx.body = res
}
}
module.exports = FileController
3. service File creation fileService.js
const Service = require('egg').Service;
class FileService extends Service{
async upload(){
const {
ctx } = this;
const files = ctx.request.files; // Get the information uploaded by the front end files Object group
const filePath = files[0].filepath.replace(/\\\\/g, "\/") // Get the temporary storage address of the file
const fileinfo = fs.readFileSync(filePath); // Read the file
const target = "E:\\development\\myProject\\pc-dev-tool\\upload\\fileName.png"; // Storage address
fs.writeFileSync(target, fileinfo) // write file
fs.unlinkSync(filePath) // Delete temporary storage files
return "ok"
}
}
module.exports = FileService
边栏推荐
- An intern's journey to cnosdb
- Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
- [template] adaptive Simpson integral
- Windows 7 install MySQL error: 1067
- How to improve data quality
- 基于全志H3的QT5.12.9移植教程
- Linux centos7 installation Oracle11g super perfect novice tutorial
- LDR6035智能蓝牙音响可充可放(5.9.12.15.20V)快充快放设备充电
- Halcon knowledge: an attempt of 3D reconstruction
- 数据分析方法论与前人经验总结【笔记干货】
猜你喜欢

Leetcode 96 différents arbres de recherche binaires

The new version of graphic network PDF will be released soon

Mysql database driver (JDBC Driver) jar package download

【QT】测试Qt是否能连接上数据库

Halcon knowledge: an attempt of 3D reconstruction

How to improve data quality

如何提升数据质量

Talents come from afar, and Wangcheng district has consolidated the intellectual base of "strengthening the provincial capital"

Relatively easy to understand PID understanding

Dongge cashes in and the boss retires?
随机推荐
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
SQL数据分析之子查询的综合用法和案例题【耐心整理】
Linux CentOS7安装Oracle11g的超完美新手教程
Jielizhi, production line assembly link [chapter]
正则表达式收集
Relevant settings of wechat applet cache expiration time (recommended)
Learn online case practice
B tree and b+tree of MySQL
Leetcode96 different binary search trees
Windows10 install WSL (I) (wslregisterdistribution error)
Vue force cleaning browser cache
Linux centos7 installation Oracle11g super perfect novice tutorial
Niuke - Practice 101 - reasoning clown
启牛学院开户安全的吗?开户怎么开?
Iota in golang
leetcode96不同的二叉搜索树
SQL Server 安装指南
S32Kxxx bootloader之UDS bootloader
Dongge cashes in and the boss retires?
下载在线视频 m3u8使用教程