1 min readDec 17, 2019
Hi.
Did you add the code for file upload?
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "./files");
},
filename: (req, file, cb) => {
cb(null, `${file.fieldname}_${+new Date()}.jpg`);
}
});const upload = multer({
storage
});
...router.post("/uploadImage", upload.single('upload'), async (req, res, next) => {
res.json({
uploaded: true,
url: `${process.env.BASE_URL}/${req.file.filename}`
});
});
This is the part that gets file from the file upload request.
On front end, I have:
<CKEditor
editor={ClassicEditor}
data={content || ""}
onInit={editor => {
if (edit) {
setContent(doc.document);
}
}}
onChange={(event, editor) => {
const data = editor.getData();
setContent(data);
setDirty(true);
}}
config={{
ckfinder: {
uploadUrl:
`${APIURL}/pdf/uploadImage`
}
}}
/>
where:
config={{
ckfinder: {
uploadUrl:
`${APIURL}/pdf/uploadImage`
}
}}
actually does the upload.