当前位置:网站首页>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
边栏推荐
- LeetCode中等题题分享(5)
- Ldr6035 smart Bluetooth audio can be charged and released (5.9.12.15.20v) fast charging and fast releasing device charging
- Is it safe to buy funds on Great Wall Securities?
- 【QT】对于Qt MSVC 2017无法编译的问题解决
- 关联性——组内相关系数
- Qt5.12.9 migration tutorial based on Quanzhi H3
- Learn online case practice
- Relevant settings of wechat applet cache expiration time (recommended)
- ADO. Net SqlConnection object usage summary
- PWN attack and defense world cgpwn2
猜你喜欢

基于全志H3的QT5.12.9移植教程

使用 ES 实现疫情地图或者外卖点餐功能(含代码及数据)

Graduation season is both a farewell and a new beginning

The new version of graphic network PDF will be released soon

【QT】對於Qt MSVC 2017無法編譯的問題解决
![[QT] QT cannot find a solution to the compiler using msvc2017](/img/80/a4b17d6cc1ab6fe1366a3a3f43ec2e.png)
[QT] QT cannot find a solution to the compiler using msvc2017

智能运维实战:银行业务流程及单笔交易追踪
![[cmake] cmake configuration in QT Creator](/img/e3/1cf76f88eaddb5d32184523dfb049c.png)
[cmake] cmake configuration in QT Creator

S32Kxxx bootloader之UDS bootloader

Example explanation: move graph explorer to jupyterlab
随机推荐
Is it safe to buy funds in a securities account? Where can I buy funds
ADO. Net SqlCommand object
RPA tutorial 01: Excel automation from introduction to practice
Database -- sqlserver details
【CTF】bjdctf_2020_babystack2
Selectively inhibiting learning bias for active sampling
. env. XXX file, with constant, but undefined
.env.xxx 文件,加了常量,卻undefined
Dongge cashes in and the boss retires?
[cascade classifier training parameters] training Haar cascades
Niuke - Practice 101 - reasoning clown
Jielizhi, production line assembly link [chapter]
Timer和ScheduledThreadPoolExecutor的区别
Iota in golang
Learn online case practice
B tree and b+tree of MySQL
ADO. Net SqlConnection object usage summary
mysql之B tree 以及 B+tree
Which app is better and more secure for stock mobile account opening
比较通俗易懂的PID理解