uppy如何将仪表板中的metaFields添加到XHRUpload

问题描述

我用

"@uppy/core": "^1.13.2","@uppy/dashboard": "^1.12.8","@uppy/xhr-upload": "^1.6.4",

和服务器端的Symfony,我遇到了一些问题,MetaFields不在服务器的元数据文件

我遵循了doc中的示例。而且我的仪表板包含MetaFields用于文件名称标题,但是当XHRUpload向服务器发送请求时,服务器中请求中的此键一无所获。我添加MetaFields:null,就像在文档-Set this to null (the default) to send all Metadata fields.中一样,但是在服务器中此键是空的,只有filesidentity 如何将MetaFields从仪表板添加到XHRUpload?

    // Import the plugins
    const Uppy = require('@uppy/core')
    const XHRUpload = require('@uppy/xhr-upload')
    const Dashboard = require('@uppy/dashboard')
    let timeOfLastAttach = new Date();
    const uppy = Uppy({
        debug: true,autoproceed: false,restrictions: {
            maxFileSize: 100097152,//100Mb
        }          
    });
    uppy.use(Dashboard,{
        trigger: '.UppyModalOpenerBtn',inline: true,target: '.DashboardContainer',replaceTargetContent: true,showProgressDetails: true,note: 'add Images',height: 470,MetaFields: [
            { id: 'name',name: 'Name',placeholder: 'file name' },{ id: 'caption',name: 'Caption',placeholder: 'describe what the image is about' }
        ],browserBackButtonClose: true
    });
    uppy.setMeta({
        id: categoryId,entity: 'Entity\\Category'
    });
    uppy.use(XHRUpload,{
        endpoint: attachment_files,formData: true,fieldName: 'files[]',bundle: true,MetaFields: null,getResponseData (responseText,response) {
            return {
                url: responseText
            }
        }
    });

这就是我在浏览器中的要求

id: 112
entity: Entity\Category
files[]: (binary)

并且在服务器文件中不包含密钥caption

这就是我在文件中拥有的

files = {array} [5]
 name = {array} [1]
  0 = "Выделение_403.png"
 type = {array} [1]
  0 = "image/png"
 tmp_name = {array} [1]
  0 = "/tmp/PHPmnkEMl"
 error = {array} [1]
  0 = {int} 0
 size = {array} [1]
  0 = {int} 145516

我尝试创建一些测试用例

    uppy.on('file-added',(file) =>{
        console.log(file);
        uppy.setFileMeta(file.id,{
            test: 'hello'
        });
    });

并且仍然在服务器端,$_FILES['files']不包含test密钥。

解决方法

您是否尝试过使用Form插件? nRF Connect App