在使用 Uppy 时,我是初学者。我相信像你这样的专业人士可以解决这个问题。但是我无法将特定的元数据信息发送到我的上传路线。
uppy.js
// Import the plugins
const Uppy = require('@uppy/core');
const XHRUpload = require('@uppy/xhr-upload');
const Dashboard = require('@uppy/dashboard');
const request = require('request');
const uppy = Uppy({
debug: true,
autoProceed: false,
restrictions: {
maxFileSize: 1024000,
maxNumberOfFiles: 3,
minNumberOfFiles: 1,
allowedFileTypes: ['image/*', 'video/*']
}
})
.use(Dashboard, {
trigger: '.UppyModalOpenerBtn',
inline: true,
target: '#drag-drop-area',
replaceTargetContent: true,
showProgressDetails: true,
proudlyDisplayPoweredByUppy: false,
animateOpenClose: true,
note: 'Images and video only, 1–3 files, up to 1 MB',
height: 470,
browserBackButtonClose: true,
theme: 'dark',
metaFields: [
{id: 'caption', name: 'Caption', placeholder: 'describe what the image is about'}
]
});
uppy.on('file-added', (file) =>{
console.log(file);
uppy.setFileMeta(file.meta.id, {
caption: file.name
});
});
uppy.use(XHRUpload, {
id: 'XHRUpload',
endpoint: 'http://localhost:8000/upload',
method: 'POST',
formData: true,
fieldName: 'my_file',
metaFields: ['caption'],
bundle: true
});
uppy.on('upload-success', (file, response) => {
//console.log(file.meta.caption);
console.log("File uploaded successfully ", file);
});
module.exports = uppy;
上传.js
router.post('/',(req, res, next) => {
console.log("Coming form uppy.js " , req.body);
});
module.exports = router;
我无法将“标题”值传递给我的路线。当我在谷歌浏览器的开发者工具上查看“网络标签”时,它给了我一条“未定义”的消息。如果您能指出我正确的方向,我将不胜感激!谢谢!