Esempio n. 1
0
        /// <summary>
        /// 视频切片
        /// </summary>
        private static void CutVideo(PutPolicy put, string key, FileTypeDirEnum dir)
        {
            var bucket = QiniuUtil.GetServerBucketHlsName(dir);

            if (bucket == String.Empty)
            {
                return;
            }

            //设置切片操作参数
            String fops = String.Format("avthumb/m3u8/segtime/10/ab/128k/ar/44100/acodec/libfaac/r/30/vb/240k/vcodec/libx264/stripmeta/0/{0}", QiniuConfig.GetWaterText());
            //设置切片的队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:{1}", bucket, key));
            String pfops     = fops + "|saveas/" + urlbase64;

            put.FsizeLimit = 1024 * 1024 * 800;

            put.PersistentNotifyUrl = QiniuConfig.UploadCallback;

            put.PersistentOps      = pfops;
            put.PersistentPipeline = pipeline;
        }
Esempio n. 2
0
        public static bool VideoCutPiece(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            //设置空间
            string bucket = QiniuUtil.GetServerBucket(dir);

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);

            //设置切片操作参数
            String fops = "avthumb/m3u8/segtime/15/vb/240k";
            //设置切片的队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:cut_{1}", bucket, key));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            return(false);
        }
Esempio n. 3
0
        public static bool DeleteServerFile(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            try
            {
                //设置空间
                string bucket = QiniuUtil.GetServerBucket(dir);

                //实例化一个RSClient对象,用于操作BucketManager里面的方法
                RSClient client = new RSClient();
                CallRet  ret    = client.Delete(new EntryPath(bucket, key));
                if (!ret.OK)
                {
                    Trace.WriteLine(ret.Response);
                    Trace.WriteLine(ret.Exception);
                }
                return(ret.OK);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            return(false);
        }
Esempio n. 4
0
        public static void WaterMarkPop(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            //设置空间
            string bucket = QiniuUtil.GetServerBucket(dir);

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);
            string    ext   = QiniuUtil.GetKeyWithExt(key);
            string    fops  = string.Format("avthumb/{0}/{1}", ext, QiniuConfig.GetWaterText());

            //设置切片的队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:{1}", bucket, key));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline, 1);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Esempio n. 5
0
        public static string GetServerVideoHlsUrl(string key, FileTypeDirEnum fileTypeDir)
        {
            string baseUrl = "";

            switch (fileTypeDir)
            {
            case FileTypeDirEnum.CrowdFundImgDir:
                baseUrl = QiniuConfig.BucketUrl.CrowdFundImgDirBaseUrl;
                break;

            case FileTypeDirEnum.CrowdFundVideoDir:
                baseUrl = QiniuConfig.BucketVideoHlsUrl.CrowdFundVideoHls;
                break;

            case FileTypeDirEnum.UserImgDir:
                baseUrl = QiniuConfig.BucketUrl.UserImgDirBaseUrl;
                break;

            case FileTypeDirEnum.UserVideoDir:
                baseUrl = QiniuConfig.BucketVideoHlsUrl.UserVideoHls;
                break;

            case FileTypeDirEnum.VideoDir:
                baseUrl = QiniuConfig.BucketVideoHlsUrl.VideoHls;
                break;

            case FileTypeDirEnum.ViderImgDir:
                baseUrl = QiniuConfig.BucketUrl.VideoImgDirBaseUrl;
                break;
            }
            return(String.Format("{0}{1}", baseUrl, key));
        }
Esempio n. 6
0
        public static string GetServerBucket(FileTypeDirEnum fileTypeDir)
        {
            switch (fileTypeDir)
            {
            case FileTypeDirEnum.CrowdFundImgDir:
                return(QiniuConfig.Bucket.CrowdFundImgDir);

            case FileTypeDirEnum.CrowdFundVideoDir:
                return(QiniuConfig.Bucket.CrowdFundVideoDir);

            case FileTypeDirEnum.UserImgDir:
                return(QiniuConfig.Bucket.UserImgDir);

            case FileTypeDirEnum.UserVideoDir:
                return(QiniuConfig.Bucket.UserVideoDir);

            case FileTypeDirEnum.VideoDir:
                return(QiniuConfig.Bucket.VideoDir);

            case FileTypeDirEnum.ViderImgDir:
                return(QiniuConfig.Bucket.VideoImgDir);

            case FileTypeDirEnum.AndroidUpdateDir:
                return(QiniuConfig.Bucket.AndroidUpdateDir);
            }
            return(String.Empty);
        }
Esempio n. 7
0
 public ImageDialog(FileTypeDirEnum fileTypeDir)
 {
     _fileTypeDir = fileTypeDir;
     InitializeComponent();
     InitAlignmentItems();
     InitBindingContext();
     InitEvents();
 }
Esempio n. 8
0
        public static ResultData UploadFileToServer(string filekey, string fpath, FileTypeDirEnum dir, bool isOverride, Action <int> proAction)
        {
            ResultData result = new ResultData();

            //设置账号的AK和SK
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            IOClient target = new IOClient();

            target.ProgressHandler += (x, y) =>
            {
                proAction?.Invoke(y.Progress);
            };
            PutExtra extra = new PutExtra();
            //设置上传的空间
            string bucket = QiniuUtil.GetServerBucket(dir);
            //设置上传的文件的key值
            string key = filekey;


            //覆盖上传,<bucket>:<key>,表示只允许用户上传指定key的文件。在这种格式下文件默认允许“修改”,已存在同名资源则会被本次覆盖。
            PutPolicy put = new PutPolicy(bucket, 3600);

            if (isOverride)
            {
                put = new PutPolicy(string.Format("{0}:{1}", bucket, key));
            }

            //VideoWaterMark(put, key, bucket);
            //调用Token()方法生成上传的Token
            string upToken = put.Token();
            //上传文件的路径
            string filePath = fpath;

            //调用PutFile()方法上传
            PutRet ret = target.PutFile(upToken, key, filePath, extra);
            //打印出相应的信息
            string json = ret.Response.ToString();

            if (json.Contains("hash") && json.Contains("key"))
            {
                ResData user = (ResData)JsonConvert.DeserializeObject(json, typeof(ResData));
                result.HashCode  = user.hash;
                result.IsSuccess = true;
                result.Key       = user.key;
                result.FullUrl   = QiniuUtil.GetFullUrl(user.key, dir);
            }
            else
            {
                result.IsSuccess = false;
                var resData = (ErrData)JsonConvert.DeserializeObject(json, typeof(ErrData));
                result.ErrCode = resData.code;
                result.ErrMsg  = resData.error;
            }

            return(result);
        }
Esempio n. 9
0
 private ResultData Upload(string filekey, string fpath, FileTypeDirEnum dir, bool isOverride, Action <int> proAction)
 {
     try
     {
         var res = ServerFileMgr.UploadFileToServer(filekey, fpath, UploadType, isOverride, proAction);
         return(res);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
     return(null);
 }
Esempio n. 10
0
        public static string GetServerBucketHlsName(FileTypeDirEnum fileTypeDir)
        {
            switch (fileTypeDir)
            {
            case FileTypeDirEnum.VideoDir:
                return(QiniuConfig.BucketVideoHls.VideoHls);

            case FileTypeDirEnum.CrowdFundVideoDir:
                return(QiniuConfig.BucketVideoHls.CrowdFundVideoHls);

            case FileTypeDirEnum.UserVideoDir:
                return(QiniuConfig.BucketVideoHls.UserVideoHls);
            }
            return(String.Empty);
        }
Esempio n. 11
0
        public static string GetFileFilter(FileTypeDirEnum fileTypeDir)
        {
            switch (fileTypeDir)
            {
            case FileTypeDirEnum.CrowdFundImgDir:
            case FileTypeDirEnum.UserImgDir:
            case FileTypeDirEnum.ViderImgDir:
                return("images |*.jpg;*.png;*.jpeg");

            case FileTypeDirEnum.UserVideoDir:
            case FileTypeDirEnum.CrowdFundVideoDir:
            case FileTypeDirEnum.VideoDir:
                return("videos |*.mp4");

            case FileTypeDirEnum.AndroidUpdateDir:
                return("videos |*.apk");
            }
            return(String.Empty);
        }
Esempio n. 12
0
        /// <summary>
        /// 处理视频缩略图
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="key"></param>
        /// <param name="fileImg"></param>
        /// <returns></returns>
        public static bool GetVideoThumbnailImg(FileTypeDirEnum dir, string key, out string fileImg)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            //设置空间
            string bucket = QiniuUtil.GetServerBucket(dir);

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);

            string name = String.Format("thumbnail-{0}.jpg", QiniuUtil.GetKeyWithoutExt(key));

            fileImg = QiniuUtil.GetFullUrl(name, dir);

            //设置操作参数
            String fops = "vframe/jpg/offset/5";
            //设置队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:{1}", bucket, name));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline);
                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }

            return(false);
        }
Esempio n. 13
0
        public static string GetFullUrl(string key, FileTypeDirEnum dir)
        {
            string baseUrl = "";

            switch (dir)
            {
            case FileTypeDirEnum.CrowdFundImgDir:
                baseUrl = QiniuConfig.BucketUrl.CrowdFundImgDirBaseUrl;
                break;

            case FileTypeDirEnum.CrowdFundVideoDir:
                baseUrl = QiniuConfig.BucketUrl.CrowdFundVideoDirBaseUrl;
                break;

            case FileTypeDirEnum.UserImgDir:
                baseUrl = QiniuConfig.BucketUrl.UserImgDirBaseUrl;
                break;

            case FileTypeDirEnum.UserVideoDir:
                baseUrl = QiniuConfig.BucketUrl.UserVideoDirBaseUrl;
                break;

            case FileTypeDirEnum.VideoDir:
                baseUrl = QiniuConfig.BucketUrl.VideoDirBaseUrl;
                break;

            case FileTypeDirEnum.ViderImgDir:
                baseUrl = QiniuConfig.BucketUrl.VideoImgDirBaseUrl;
                break;

            case FileTypeDirEnum.AndroidUpdateDir:
                baseUrl = QiniuConfig.BucketUrl.AndroidUpdateDirBaseUrl;
                break;
            }
            return(String.Format("{0}{1}", baseUrl, key));
        }
Esempio n. 14
0
 public void BindUploadType(FileTypeDirEnum e)
 {
     TextHtml.UploadType = e;
 }
Esempio n. 15
0
 public void DeleteServerFile(string key, FileTypeDirEnum dir)
 {
     ServerFileMgr.DeleteServerFile(dir, key);
 }