2

我用

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

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

我按照文档中的示例进行操作。我的仪表板包含metaFields文件、名称和标题,但是当XHRUpload向服务器发送请求时,我对服务器请求中的这个键一无所知。我添加了 metaFields: null,就像在 doc - 中一样Set this to null (the default) to send all metadata fields.,但在服务器中只有这个键是空的filesid以及entity 如何metaFields从 Dashboard 添加到 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密钥。

4

1 回答 1

0

您是否尝试过使用表单插件? https://uppy.io/docs/transloadit/#fields

于 2020-10-21T06:26:12.207 回答