七牛云存储之应用视频上传系统开心得

  • 七牛云存储

        七牛云存储(以下简称七牛),是专为移动时代开发者打造的数据管理平台,为互联网网站和移动App提供数据的在线托管、传输加速以及图片、音视频等富媒体的云处理服务。

  •  产品特性

        1.数据的在线托管

           七牛采用全分布式系统架构以及存储技术,主要存储图片、音视频等静态文件,并对数据实行多机房互备和跨IDC修复,从而保障数据存储的安全性。

        2.数据的传输加速

          七牛支持上传/下载双向加速,对于单个文件的上传没有大小限制,并且支持断点续传。七牛在全国部署了500多个加速节点,用户可以选择任意的IDC就近上传下载

        3.云端数据处理

         七牛提供丰富的图片处理服务,例如缩略图、图文混排、水印、自定义裁剪区域、防盗链,原图保护等。七牛还支持常见的ffmpeg音视频格式转换,视频取帧以及流媒体传输协议(HLS)。

        4.提供了10G存储空间,就一个月也是10G的流量

  •     应用心得

         1.官方提供比较全面的SDK,不过对于C#SDK来说,有些地方还没有完善,如持久性格式转化存储

         2.有时候返回进度值百分比超过100%的BUG,需要自己的修改SDK

         3.没有提供以编程的方式创建空间,在提供给多用户使用时,只能通过修改文件前缀来处理

         4.上传核心代码

             

  string[] files = Dialog.FileNames;//所有文件
                BindingList<UpLoadInfo> UpLoadFileCurr = GrUpLoadList.DataSource as BindingList<UpLoadInfo> ?? new BindingList<UpLoadInfo>();//当前列表里的数据
                var FileCurr = files.Where(f => ActSize(f) != 0 && (UpLoadFileCurr.Count == 0 || !UpLoadFileCurr.Any(UF => UF.FileName == f))).Select(key => new UpLoadInfo() { FileName = key, UpLoadState = "待上传", FileSize = ActSize(key), UpLoadType = UpLoadType.NotUpload }).ToList();//过滤相同的文件名
View Code

     5读取数据列表代码
     

  RSFClient target = new RSFClient(UserInfo.Bucket); // TODO: 初始化为适当的值
                target.Marker = UserInfo.Prefix;
                target.Prefix = UserInfo.Prefix;
                target.Limit = -1;
                DumpRet actual = target.ListPrefix(UserInfo.Bucket, UserInfo.Prefix);
                List<FileInfo> fileList = new List<FileInfo>();
                Func<long, DateTime> fun = (lTime) =>
                {
                    DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                    TimeSpan toNow = new TimeSpan(lTime);
                    return dtStart.Add(toNow);
                };
                int Index = 0;
                Func<int> getindex = () =>
                {
                    return ++Index;
                };
                //大小字节转为KB
                Func<long, decimal> ActSize = (filesize) =>
                {
                    decimal reSize = (decimal)filesize / 1024;
                    int m = reSize > 1 ? 0 : 2;
                    return Math.Round(reSize, m);
                };
                Func<string, string> FunFileName = (filename) =>
                {
                    int Pos = UserInfo.CurrShowId.ToString().Length + 1;
                    return filename.Substring(Pos, filename.Length - Pos);
                };
                if (actual.Items == null) actual.Items = new List<DumpItem>();
                var Binding = new BindingList<FileInfo>(actual.Items.Select(f => new FileInfo() { FileName = FunFileName(f.Key), CreateTime = fun(f.PutTime), FileSize = ActSize(f.FSize), Id = getindex() }).ToList());
                Action actBind = () =>
                {

                    grList.DataSource = Binding;
                    GrLoading.Stop();
                    GrLoading.Hide();

                };

                base.Invoke(actBind);
View Code

     

原文地址:https://www.cnblogs.com/gzalrj/p/3399810.html