【问题标题】:How to pass meta data using Uppy's Dashboard plugin如何使用 Uppy 的 Dashboard 插件传递元数据
【发布时间】:2020-05-08 09:13:18
【问题描述】:

我是使用 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;

我无法将“标题”值传递给我的路线。当我在谷歌浏览器的开发者工具上查看“网络标签”时,它给了我一条“未定义”的消息。如果您能指出我正确的方向,我将不胜感激!谢谢!

【问题讨论】:

    标签: javascript node.js uppy


    【解决方案1】:

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

    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,那么您将面临对每个文件的单独请求,但所有元数据都将出现在请求中

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2020-06-30
      • 1970-01-01
      相关资源
      最近更新 更多