config.multipart = {
mode: 'file'
};
const fs = require('fs');
const path = require('path');
async update(){
const {ctx} =this
const file=ctx.request.files[0]
const fileinfo = fs.readFileSync(file.filepath);
const target = path.join(`app/public/uploads`,file.filename);
try {
await fs.writeFileSync(target, fileinfo);
} catch (error) {
throw error;
} finally {
await fs.unlink(file.filepath, err => {
if (err) {
throw err;
}
console.log('删除缓存文件:' + file.filepath + '成功!');
});
}
ctx.body = {
url: 'http://' + ctx.host + `/public/uploads/${file.filename}`
};
}