首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Uppy的Dashboard插件传递元数据

如何使用Uppy的Dashboard插件传递元数据
EN

Stack Overflow用户
提问于 2020-05-08 17:13:18
回答 1查看 574关注 0票数 1

当涉及到使用Uppy时,我是一个初学者。我相信像你这样的专业人士可以解决这个问题。但是我在向我的上传路线发送特定的元数据信息时遇到了问题。

uppy.js

代码语言:javascript
复制
// 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;

upload.js

代码语言:javascript
复制
router.post('/',(req, res, next) => {

  console.log("Coming form uppy.js " , req.body);

});

module.exports = router;

我在将'caption‘值传递给我的路线时遇到问题。当我查看Google Chrome开发者工具的“网络标签”时,它给我一条“未定义”的信息。如果你能给我指出正确的方向,我将不胜感激!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-07 22:10:27

首先,需要将file.meta.id更改为file.id

代码语言:javascript
复制
uppy.on('file-added', (file) =>{
    console.log(file);
    uppy.setFileMeta(file.id, {
        test: 'hello'
    });
});

但是如果你使用bundle,你应该知道这个注释

Note: When bundle is set to true, only global uppy metadata, the one set via meta options property, is sent to the endpoint. Individual per-file metadata is ignored.

因此,如果您希望为每个文件发送元数据,则应将其更改为false,然后您将面临针对每个文件单独请求,但所有元数据都将出现在请求中

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61675791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档