uppy how to add metaFields from Dashboard to XHRUpload

2.1k views Asked by At

I use

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

and Symfony in server side and I faced with some problem, metaFields not present in meta data file in server

I followed to example from doc. And my dashboard contains metaFields for files, name and caption, but when XHRUpload send request to server I got nothing about this keys in request in server. I added metaFields: null, like in doc - Set this to null (the default) to send all metadata fields., but in server had empty about this keys, only files, id and entity How to add metaFields from Dashboard to 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
            }
        }
    });

this is what I have in request in browser

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

and in server files did not contains key caption

this what I have in files

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

I try to create some test case

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

and still in server side, $_FILES['files'] did not contains test key.

1

There are 1 answers

0
Florin On

Have you tried using the Form plugin? https://uppy.io/docs/transloadit/#fields