javascript - Dropzone 发送空

标签 javascript dropzone.js

我有一个带有以下脚本的拖放区设置:

    <script>
    Dropzone.options.myDropzone = {
        url: 'assets/PHP/createNieuws.php',
        autoProcessQueue: false,
        uploadMultiple: true,
        parallelUploads: 1,
        maxFiles: 1,
        maxFilesize: 1,
        acceptedFiles: 'image/*',
        addRemoveLinks: true,
        createImageThumbnails: true,
        init: function () {
            dzClosure = this; // Makes sure that 'this' is understood inside the functions below.

            this.on("success", function (file, responseText) {
                console.log(responseText);
            });

            // for Dropzone to process the queue (instead of default form behavior):
            document.getElementById("submit").addEventListener("click", function (e) {
                // Make sure that the form isn't actually being sent.
                e.preventDefault();
                e.stopPropagation();
                if (dzClosure.getQueuedFiles().length > 0) {
                    dzClosure.processQueue();
                } else {
                    dzClosure.uploadFiles([{ name: 'nofiles' }]); //send empty
                }
            });

            //send all the form data along with the files:
            this.on("sendingmultiple", function (data, xhr, formData) {
                formData.append("titel", jQuery("#titel").val());
                formData.append("artikel", jQuery("#artikel").val());
            });
        }
    }
</script>

我的服务器上还有一个名为 default.png 的文件。如果没有检测到图像,我希望 dropzone 引用 default.png 。正如你所看到的,我已经尝试过这个解决方案但没有成功:https://stackoverflow.com/a/41044001/6396380

这会在我的 Chrome 控制台中返回以下错误:

dropzone.js:1497 未捕获类型错误:无法读取未定义的属性“文件名”

我的 dropzone 版本是 5.1.0 。

有什么办法可以解决这个问题吗?

最佳答案

发生这种情况是因为新版本假设存在一个带有filenamefile.upload对象。将您的模拟文件更改为

{ name: 'nofiles', upload: { filename: 'nofiles' } }

应该可以解决问题。

您还应该升级到 5.1.1,因为它解决了与此相关的错误。

关于javascript - Dropzone 发送空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44656605/

相关文章:

javascript - 具有更新默认颜色的 Highcharts 气泡图

javascript - jquery 和 javascript 过滤问题

javascript - Dropzone.js - 上传后的成功消息

javascript - dropzone Nodejs文件上传

javascript - 检查 dropzone 中的文件类型

javascript - 如何使用 Dropzonejs 将 Android 画廊中的照片上传到网站?

javascript - 删除内部没有 <img> 的 DOM 生成元素

javascript数组推送问题

javascript - 为什么我的 reactJs 没有重新渲染

javascript - 使用 dropzone.js 将文件直接上传到 Azure Blob 存储(使用 SAS)