首页 > 代码库 > 七牛上传视频并转码
七牛上传视频并转码
/// <summary> /// 上传视频到七牛并转码 /// </summary> /// <param name="saveKey"></param> /// <param name="localFile"></param> public static void UpLoadVideo(string saveKey, string localFile) { Mac mac = new Mac(ACCESS_KEY, SECRET_KEY); PutPolicy putPolicy = new PutPolicy(); // 如果需要设置为"覆盖"上传(如果云端已有同名文件则覆盖),请使用 SCOPE = "BUCKET:KEY" // putPolicy.Scope = bucket + ":" + saveKey; putPolicy.Scope = bucket; // 上传策略有效期(对应于生成的凭证的有效期) putPolicy.SetExpires(3600); putPolicy.PersistentPipeline = "UpLoadVideo"; //进行视屏转码 (转成 mp4 资源和对原资源进行 HLS 切片) putPolicy.PersistentOps = "avthumb/mp4;avthumb/m3u8/noDomain/1/segtime/15/vb/440k"; // 上传到云端多少天后自动删除该文件,如果不设置(即保持默认默认)则不删除 //putPolicy.DeleteAfterDays = 1; // 生成上传凭证,参见 // https://developer.qiniu.com/kodo/manual/upload-token //string jstr = putPolicy.ToJsonString(); string token = Auth.createUploadToken(putPolicy, mac); UploadOptions uploadOptions = null; // 上传完毕事件处理 UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted); // 方式1:使用UploadManager //默认设置 Qiniu.Common.Config.PUT_THRESHOLD = 512*1024; //可以适当修改,UploadManager会根据这个阈值自动选择是否使用分片(Resumable)上传 UploadManager um = new UploadManager(); um.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted); //HttpResult result = um.uploadFile(localFile, saveKey, token); } public static void UpLoadImg(string saveKey, string localFile) { Mac mac = new Mac(ACCESS_KEY, SECRET_KEY); PutPolicy putPolicy = new PutPolicy(); // 如果需要设置为"覆盖"上传(如果云端已有同名文件则覆盖),请使用 SCOPE = "BUCKET:KEY" // putPolicy.Scope = bucket + ":" + saveKey; putPolicy.Scope = bucket; // 上传策略有效期(对应于生成的凭证的有效期) putPolicy.SetExpires(3600); putPolicy.PersistentPipeline = "UpLoadVideo"; //进行视屏转码 (转成 mp4 资源和对原资源进行 HLS 切片) //putPolicy.PersistentOps = "avthumb/mp4;avthumb/m3u8/noDomain/1/segtime/15/vb/440k"; // 上传到云端多少天后自动删除该文件,如果不设置(即保持默认默认)则不删除 //putPolicy.DeleteAfterDays = 1; // 生成上传凭证,参见 // https://developer.qiniu.com/kodo/manual/upload-token //string jstr = putPolicy.ToJsonString(); string token = Auth.createUploadToken(putPolicy, mac); UploadOptions uploadOptions = null; // 上传完毕事件处理 UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted); // 方式1:使用UploadManager //默认设置 Qiniu.Common.Config.PUT_THRESHOLD = 512*1024; //可以适当修改,UploadManager会根据这个阈值自动选择是否使用分片(Resumable)上传 UploadManager um = new UploadManager(); um.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted); //HttpResult result = um.uploadFile(localFile, saveKey, token); } private static void OnUploadCompleted(string key, ResponseInfo respInfo, string respJson) { Logger.LogHelper.WriteInfoLog(respJson); // respInfo.StatusCode // respJson是返回的json消息,示例: { "key":"FILE","hash":"HASH","fsize":FILE_SIZE } } /// <summary> /// 七牛空间名 /// </summary> public static string qnSpace { get { return ConfigurationManager.AppSettings["qnSpace"]; } } /// <summary> /// 项目名 /// </summary> public static string itemname { get { return ConfigurationManager.AppSettings["itemname"]; } } /// <summary> /// 外链地址 /// </summary> public static string outlink { get { return ConfigurationManager.AppSettings["outlink2"]; } }
关于一些配置方面需要注意的问题参考http://www.cnblogs.com/chongyao/p/6644970.html
七牛上传视频并转码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。