使用 Dropzone 通过 asp.net 上传两次 [英] Using Dropzone to upload twice with asp.net

查看:22
本文介绍了使用 Dropzone 通过 asp.net 上传两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 dropzone 上传文件.首先我会在用户上传他/她的文件时检查这个文件格式,所以我想我需要设置autoProcessQueue:true",以便自动检查上传的文件.如果文件格式不正确,将要求用户重新上传,直到上传正确的文件.

然后当用户点击保存"按钮时,这个文件将上传到我的服务器.

我的 javascript 代码如下:

Dropzone.options.myDropzone = {自动处理队列:真,addRemoveLinks: 真,maxFilesize: 2,//MB接受的文件:.xlsx",最大文件数:1,url: 'MyPage.aspx?File=<%=Request.QueryString["File"]%>',初始化:函数(){this.on(添加文件",函数(){如果 (this.files[1] != null) {this.removeFile(this.files[0]);}});$('#_btnTest').click(function () {警报('aaa')myDropzone.processQueue();警报('bbb')});},};

我的aspx代码

<div class="fallback"><input name="file" type="file" runat="server"/>

<asp:Button ID="_btnSave" runat="server" Text="Save" class="btn btn-info btn-sm" OnClick="_btnSave_Click"/>

下面是我的 C# 代码

protected void Page_Load(object sender, EventArgs e){if (Request.QueryString["File"] != null){检查格式();}}

当我上传文件时,它会运行CheckFormat()"方法并自动检查.但我的问题是当我点击保存"按钮时不会运行 Page_Load() 方法,所以我无法在代码隐藏中获取文件,这个问题让我在点击保存"按钮时无法上传文件.顺便说一句,我猜myDropzone.processQueue();"无效.

您对此案的解决方案是什么?当您想先检查文件然后在用户单击按钮时将此文件保存到服务器时该怎么办?请帮助我,非常感谢.

解决方案

当您的第一次上传请求完成后,文件状态将变为成功",在这种情况下,再次提交上传请求时将跳过此文件.

解决办法:将文件状态更改为排队",以便再次上传.类似于以下内容:

this.on(" addedfile", function (file) {如果 (this.files[1] != null) {this.removeFile(this.files[0]);} 别的 {file.status = '排队';}});

I want to upload file by using dropzone. First I will check this file format when user upload his/her file, so I guess I need to set "autoProcessQueue: true" so that the uploaded file will be checked automatically. If the file format is not right, user will be asked to upload again until upload right file.

Then when user click "save" button, this file will be uploaded into my server.

My javascript code is below:

Dropzone.options.myDropzone = {
        autoProcessQueue: true,
        addRemoveLinks: true,
        maxFilesize: 2, // MB
        acceptedFiles: ".xlsx",
        maxFiles: 1,
        url: 'MyPage.aspx?File=<%=Request.QueryString["File"]%>',
        init: function () {
            this.on("addedfile", function () {                
                if (this.files[1] != null) {
                    this.removeFile(this.files[0]);
                }
            });

            $('#_btnTest').click(function () {
                alert('aaa')
                myDropzone.processQueue();
                alert('bbb')
            });

        },
};

My aspx code

<div id="myDropzone" class="dropzone">
<div class="fallback">   
<input name="file" type="file" runat="server" />
</div>
</div>
    <asp:Button ID="_btnSave" runat="server" Text="Save" class="btn btn-info btn-sm" OnClick="_btnSave_Click" />

My C# code below

protected void Page_Load(object sender, EventArgs e)
    {
                    
       if (Request.QueryString["File"] != null)
       {
           CheckFormat();
       }            
    }

When I upload file it will run "CheckFormat()" method and check automatically. But my problem is that when I click "save" button will not run Page_Load() method, so I can't get the file in code-behind, this problem let me can not upload file when click "save" button. By the way, I guess "myDropzone.processQueue();" is invalid.

what is your solution about this case? How to do when you want to check file first then save this file to server when user click button? Please help me and thank you so much.

解决方案

When your first upload request finished, file status will become "success", in which case, this file will be skipped when you submit upload request again.

Solution: Change file status to "queued" so it will be upload again. Something like following:

this.on("addedfile", function (file) {                
                if (this.files[1] != null) {
                    this.removeFile(this.files[0]);
                } else {
                    file.status = 'queued';
                }
            });

这篇关于使用 Dropzone 通过 asp.net 上传两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#/.NET最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆