我想在 MongoDB 中存储一个 PDF 文件并使用 react 和 express 检索它。但是在我使用 #app
方法的 express 文件中,它抛出 500 fs.readfilesync(...)
。
反应文件:
(Internal Server Error)
猫鼬模式:
const fd = new FormData();
fd.append("file", e.target.files[0]);
fd.set("data", e.target.title.value);
axios
.post(url, fd)
.then(...)
.catch(...);
快递文件:
const mongoose = require('mongoose');
const fileSchema = new mongoose.Schema({
title: String,
pdf: {
data: Buffer,
contentType: String
}
})
module.exports = new mongoose.model('File', fileSchema);