ucdavis/CaesHelp

dropzone workaround

Opened this issue · 2 comments

Drag and drop doesn't work. As a workaround, this might:

onDrop(acceptedFiles, rejectedFiles, e) {
    this.setState({
        files: acceptedFiles,
        filesWereDropped: !e.target.files || e.target.files.length === 0
    });
}
onSubmit(e) {
    e.preventDefault();
    let formData = new FormData(this.formRef);

    if (this.state.filesWereDropped) {
        /* if the file input has no files, check state for files and add
         * those to the form data. This is necessary because dragging
         * and dropping does set the files property of the file input,
         * and it is not possible to set it from javascript for
         * security reasons.
         */
        this.state.files.forEach(file => {
            formData.append('myfiles', file, file.name);
        });
    }

    // then POST your formData!
}

From here:
react-dropzone/react-dropzone#131

Nice! is this still needed? came across the exact same problem today where I just assumed it'd be in the files array after dropping.

Nice! is this still needed? came across the exact same problem today where I just assumed it'd be in the files array after dropping.

Haven't looked at it since. I think we are still having issues with it.