ucdavis / CaesHelp

Help Request system written in .Net Core
MIT License
0 stars 0 forks source link

dropzone workaround #64

Open jSylvestre opened 3 years ago

jSylvestre commented 3 years ago

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: https://github.com/react-dropzone/react-dropzone/issues/131

james-gardner commented 2 years ago

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.

jSylvestre commented 2 years ago

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.