Metadata for whole upload using Uppy dashboard

153 Views Asked by At

Is there a way to add custom metadata to a whole upload, that is, not on individual files, using the Uppy Dashboard?

I can see there is a separate form plugin but my understanding that this cannot be used in connection with the dashboard.

1

There are 1 best solutions below

0
WhatTheWhat On

The forms plugin CAN be used with the dashboard plugin. The following code allowed me to attach custom metadata along with the upload:

import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard';
import Tus from '@uppy/tus'
import GoldenRetriever from '@uppy/golden-retriever';
import Form from '@uppy/form';
import '@uppy/core/dist/style.css'
import '@uppy/drag-drop/dist/style.min.css';
import '@uppy/dashboard/dist/style.min.css';

const uppy = new Uppy({
    debug: true,
    autoProceed: false,
    restrictions: {
        maxTotalFileSize: 5000000000
    },
    onBeforeFileAdded: (currentFile) => {
        const isCorrectExtension = currentFile.name.endsWith('.xml')
        if (isCorrectExtension) {
            uppy.info(".xml files are not allowed")
            return false
        } else {
            return true
        }
    }
})

uppy.use(Dashboard, {
    inline: true,
    note:"No .XML files, Total file size 5GB or less",
    target: '#uppy-dashboard',
    proudlyDisplayPoweredByUppy: false,
    showProgressDetails: true,
    fileManagerSelectionType:"both",
    hideProgressAfterFinish: false,
    hideUploadButton: true,
    height:"15em",
})

uppy.use(Form, {
        target: "#my-form",
        resultName: 'uppyResult',
        getMetaFromForm: true,
        addResultToForm: true,
        submitOnSuccess: false,
        triggerUploadOnSubmit: true,
    })


uppy.use(Tus, { endpoint: 'http://0.0.0.0:8181/files'});
uppy.use(GoldenRetriever);