web下载文件夹

一般10M以下的文件上传通过设置Web.Config,再用VS自带的FileUpload控件就可以了,但是如果要上传100M甚至1G的文件就不能这样上传了。我这里分享一下我自己开发的一套大文件上传控件供大家参考

这是前端代码:

<body>
    <div id="app">
  {{ message }}
          <http-uploader6></http-uploader6>
    </div>
    <script type="text/javascript">
        // 定义一个名为 button-counter 的新组件
        Vue.component('http-uploader6', {
            data() {
                return {
                    upApp: null
                }
            },
            mounted() {
                //初始化up6
                const _this = this;
                this.upApp = new HttpUploaderMgr();
                this.upApp.load_to("up6-div");
            },
            destoryed() {
                //this.editor.destory();
            },
            methods: {
                open_file: function () { this.upApp.openFile(); }
                , open_folder: function () { this.upApp.openFolder(); }
            },
            template: '<div id="up6-div"></div>'
        });
 
        var app = new Vue({
            el: '#app',
            data: {
                message: '演示up6如何在vue中使用'
            }
        });
    </script>
</body>

这是部分报错信息

 

这是后台部分代码和截图:

文件上传完毕,f_complete.

文件初始化,f_create

文件块处理,f_post

文件夹上传完毕,fd_complete

文件夹初始化,fd_create

 

using System.Web;
using up6.db.model;
 
namespace up6.db.biz
{
    /// <summary>
    /// 路径生成器基类
    /// 提供文件或文件夹的存储路径
    /// </summary>
    public class PathBuilder
    {
        /// <summary>
        /// 根级存储路径,
        /// </summary>
        /// <returns></returns>
        public string getRoot()
        {
            return HttpContext.Current.Server.MapPath("/upload");
        }
 
        public virtual string genFolder(ref FileInf fd)
        {
            return string.Empty;
        }
 
        public virtual string genFile(int uid, ref FileInf f)
        {
            return string.Empty;
        }
        public virtual string genFile(int uid, string md5, string nameLoc)
        {
            return string.Empty;
        }
    }
}

文件和文件夹批量上传

 

当网络问题导致传输错误时,只需要重传出错分片,而不是整个文件。另外分片传输能够更加实时的跟踪上传进度。

 

上传成功后打开我们的存储文件夹查看,发现自动生成了几个文件夹,打开文件夹确认上传文件成功

 

文件及文件夹批量下载

这是下载所需的脚本截图和部分代码:

using System;
using System.IO;
using System.Web;
 
namespace up6.down2.db
{
    public partial class f_down : System.Web.UI.Page
    {
        bool check_params(params string[] vs)
        {
            foreach(string v in vs)
            {
                if (String.IsNullOrEmpty(v)) return false;
            }
            return true;
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            string id           = Request.Headers["id"];//文件id
            string blockIndex   = Request.Headers["blockIndex"];//基于1
            string blockOffset  = Request.Headers["blockOffset"];//块偏移,相对于整个文件
            string blockSize    = Request.Headers["blockSize"];//块大小(当前需要下载的)
            string pathSvr      = Request.Headers["pathSvr"];//文件在服务器的位置
            pathSvr             = HttpUtility.UrlDecode(pathSvr);
 
            if ( !this.check_params(id,blockIndex,blockOffset,pathSvr))
            {
                Response.StatusCode = 500;
                return;
            }
 
            Stream iStream = null;
            try
            {
                // Open the file.
                iStream = new FileStream(pathSvr, FileMode.Open, FileAccess.Read, FileShare.Read);
                iStream.Seek(long.Parse(blockOffset),SeekOrigin.Begin);//定位
 
                // Total bytes to read:
                long dataToRead = long.Parse(blockSize);
 
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Length", blockSize );
 
                int buf_size = Math.Min(1048576, int.Parse(blockSize));
                byte[] buffer = new Byte[ buf_size];
                int length;
                while (dataToRead > 0)
                {
                    // Verify that the client is connected.
                    if (Response.IsClientConnected)
                    {
                        // Read the data in buffer.
                        length = iStream.Read(buffer, 0, buf_size);
                        dataToRead -= length;
 
                        // Write the data to the current output stream.
                        Response.OutputStream.Write(buffer, 0, length);
 
                        // Flush the data to the HTML output.
                        Response.Flush();
                    }
                    else
                    {
                        //prevent infinite loop if user disconnects
                        dataToRead = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                // Trap the error, if any.
                Response.Write("Error : " + ex.Message);
            }
            finally
            {
                if (iStream != null)
                {
                    //Close the file.
                    iStream.Close();
                }
            }
 
        }
    }
}

首先勾选多个上传的文件或文件夹,你会发现多了一个下载按钮

然后点击下载按钮,设置下载目录文件夹

设置完成后继续点击下载按钮,页面的右下角出现了下载面板,你选择的文件已出现在目录中,然后点击全部下载,或者单个点击继续,自动加载未上传完的任务。在刷新浏览器或重启电脑后任然可以自动加载未完成的任务

 

下载完成后打开我们设置的下载目录文件夹,发现需下载的文件或文件夹确认已下载成功,经确认文件夹内的内容与下载文件夹内容一致

 

数据库记录

其他产品截图:

 

产品介绍官网:https://dwz.cn/fgXtRtnu

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值