• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

FileServices: 文件管理,超大文件上传,服务端支持断点续传,客户端h5上传器,支持多 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

FileServices

开源软件地址:

https://gitee.com/ufangx/FileServices

开源软件介绍:

FileServices

文件管理,超大文件上传,服务端支持断点续传,客户端h5上传器,支持多文件同时上传,支持断点续传

使用方法

  1. 注册服务
        public void ConfigureServices(IServiceCollection services)        {                        services.AddHttpContextAccessor();            services.AddFileServices(opt => {                opt.DefaultScheme = "documents";//默认是文档处理方案                opt.AddAuthenticationScheme(CookieAuthenticationDefaults.AuthenticationScheme);//身份认证方案名称                //文件保存时新文件的命名规则                opt.RuleOptions = new Ufangx.FileServices.Models.FileNameRuleOptions()                {                    Rule = Ufangx.FileServices.Models.FileNameRule.Custom,//自定义命名规则,必须提供自定义方法                    Custom = originFileName => string.Format("{0:yyyyMMddHHmmss}_xx_{1}", DateTime.Now, originFileName),                    Format = "xxx_{0:yyyyMMddHHmmss}"//这个配置和Rule=FileNameRule.Date一起使用,默认是:{0:yyyyMMddHHmmss}                };            })                //照片处理方案                .AddScheme("pictures", opt => {                    opt.StoreDirectory = "wwwroot/pictures";//图片存储的目录,使用本地文件系统时一般不放这里                    opt.SupportExtensions = new string[] { ".jpg", ".png" };//支持的扩展名                    opt.HandlerType = null;//上传成功后的文件处理类型,该类型必须实现IFileHandler接口                    opt.LimitedSize = 1024 * 1024 * 4;//文件大小的最大限制值,字节为单位                })                .AddScheme("documents",opt => opt.StoreDirectory = "wwwroot/documents")//文档处理方案                .AddScheme<VideoService>(name:"videos",                storeDirectory:"wwwroot/videos",//视频存储目录,使用本地文件系统时一般不放这里                supportExtensions: new string[] { ".avi", ".wmv", ".mpg", ".mpeg", ".mov", ".rm", ".swf", ".flv", ".mp4" }                LimitedSize:1024*1024*500)//视频处理方案                //.AddLocalServices(o => o.StorageRootDir = hostEnvironment.ContentRootPath)//本地文件系统,文件存在本地                //七牛存储服务                .AddQiniuFileService(opt => {                    opt.AccessKey = "";//                    opt.SecretKey = "";                    opt.BasePath = "";                    opt.Bucket = "";                    opt.Domain = "";                    opt.ChunkUnit = Qiniu.Storage.ChunkUnit.U1024K;                    opt.Zone = "ZoneCnEast";                                });                //续传信息默认是存储在缓存里面,通过services.AddDistributedRedisCache方法配置Redis缓存实现持久化存储                //或者AddQiniuFileService<CustomResumableInfoService>或者AddLocalServices<CustomResumableInfoService> 方法指定自定义续传信息服务类型        }        

2.使用中间件

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)        {              //。。。。其他代码                               app.UseFileServices("/FileServices");                 //上传文件的url是:/FileServices/uploader                 //创建续传信息是:                 //GET /FileServices/uploader?fileSize=125829120&blobSize=4194304&blobCount=30&fileName=xxx.zip&fileType=xxxx                 //request headers                 //scheme:documents                 //response                 //{"index":0,"key":"续传信息key"}                 //获取续传信息是:                  //GET /FileServices/uploader?key=续传信息key                 //request headers                 //scheme:documents                 //response                 //{"index":12,"key":"续传信息key"}                 //删除续传信息是:                 //DELETE /FileServices/uploader?key=续传信息key                 //response                 //true                 //上传切片数据块                 //POST  /FileServices/uploader                 //Form                 //blobIndex:12 当前切片的索引                 //key:续传信息key                 //Form.Files==1 必须有一个表单文件,表示当前切片数据                 //request headers                 //scheme:documents                 //上传文件                 //POST  /FileServices/uploader                 //Form.Files>0 必须包含有一个文件以上                 //request headers                 //scheme:documents                                       //。。。。其他代码                }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap