我有以下代码:
router.js router.post("/upload", users.authenticateToken, things.uploadImage);
things.controller.js
const multer = require("multer") const path = require('路径');
const 存储 = multer.diskStorage({ 目的地: '。/', 文件名:函数(请求,文件,cb){ console.warn('xxxx', 文件) cb(null, Date.now() + '.' + file.mimetype.split('/')[1]) } }) const upload = multer({ storage: storage });
// 从数据库中检索所有事物。 exports.uploadImage = (upload.single('file'), (req, res) => { console.warn('它被调用了'); });
Thing.html
<div class="div border p-2">
<div class="row">
<div class="col">
<div class="form-outline mb-4">
<label class="form-label" for="phone">Images</label>
<input #fileInput type="file" name="image" id="price" placeholder="Enter price here..."
formControlName="thumbnail" (change)="selectFile($event)" class="form-control" />
<br />
<button (click)="onFileUpload()">Upload</button>
</div>
</div>
</div>
</div>
当我点击上传时它确实显示“它被调用”,但是它没有调用下面的内容并且文件没有上传:
console.warn('xxxx', file)
我错过了什么?