Dropzone文件未处理

时间:2017-07-17 20:49:14

标签: javascript html dropzone.js

我试图让一个简单的Dropzone框工作,我似乎已经设置了所有东西,虽然我试图上传的文件永远不会上传。但是,我没有任何错误,所以我真的不知道在哪里看。以下是我的代码的相关部分:

制作Dropzone表单的HTML

    Dropzone.options.demoUpload = {
    paramName: "file", // The name that will be used to transfer the file
    maxFilesize: 1000, // MB'
    maxFiles: 1,

    init: function() {
      this.on("addedfile", function(file) { alert("File added.");});
    }
  };

JS for Dropzone element

Range(myRange).HorizontalAlignment = xlRight

dropzone在浏览器中显示正常,但是当我将文件拖到它上面时,它看起来好像文件在dropzone中,但缩略图只显示我图像的一半而进度条保持为零。这是它的样子。

Screenshot of what the Dropzone looks like after I drag in a file

File I am trying to upload

(我试图上传的文件实际上是一个.svg文件,但我不能在这篇帖子中附上,所以我认为.png就足够了。它们看起来很相似。)

如果有人能帮我弄清楚我需要改变什么才能正确上传文件,我将非常感激。谢谢!

1 个答案:

答案 0 :(得分:2)

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>IndexStackOverflow101</title>
    <link href="~/Content/dropzone.css" rel="stylesheet" />
    <style type="text/css">
        .dropzone {
            border: 2px dashed #0087F7;
            border-radius: 5px;
            background: white;
        }
    </style>
    <script src="~/Scripts/dropzone.js"></script>
</head>
<body>
    @*changed the id*@
    <form action="/" class="dropzone" enctype="multipart/form-data" id="demoUpload" method="post">
        <div class="dz-message needsclick">
            "Drop SVG Files Here or Click to Upload"
            <br>
            <span class="note needsclick">
                "Only SVG filetypes are accepted. Rasterized img filetypes coming soon."
            </span>
        </div>
    </form>
    <script type="text/javascript">
        //YOU have a dash in the form id, please change it
        Dropzone.options.demoUpload = {
            paramName: "file", // The name that will be used to transfer the file
            maxFilesize: 1000, // MB'
            maxFiles: 1,

            init: function () {
                this.on("addedfile", function (file) { alert("File added."); });
            }
        };
    </script>
</body>
</html>