private dynamic BannerCallBack(JObject postData) { string type = postData.Value <string>("BusinessType"); string fileKey = postData.Value <string>("key"); string guidName = Guid.NewGuid().ToString("N") + ".jpg"; string saveBigAs = type + "_" + guidName; if (SaveAsImage(fileKey, saveBigAs)) { string imgPara = "imageMogr2/thumbnail/318/crop/!200x96a59a0"; string smallThumbKey = type + "_small_" + guidName; string thumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + smallThumbKey); string thumbsaveas = "|saveas/" + thumbencodedEntryURI; string imgFops = imgPara + thumbsaveas; Pfop pfop = new Pfop(); string pileline = GetPipeline(); PfopDo(pfop, publicBucket, saveBigAs, imgFops, pileline, smallThumbKey, 0); return(new { bigKey = saveBigAs, smallKey = smallThumbKey }); } return(new { bigKey = saveBigAs, smallKey = saveBigAs }); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> private string _sign(byte[] data) { HMACSHA1 hmac = new HMACSHA1(SecretKey); byte[] digest = hmac.ComputeHash(data); return(Base64URLSafe.Encode(digest)); }
/// <summary> /// Amr文件转Mp3 /// </summary> /// <param name="fileName">文件名,aa.amr</param> /// <param name="stream">文件流</param> /// <param name="notifyUrl">七牛转码成功后用于接收通知的url</param> /// <returns>文件外链</returns> public static async Task <string> PutAmrToMp3Async(string fileName, Stream stream, string notifyUrl) { PutPolicy policy = new PutPolicy(_bucket, 3600); PutExtra extra = new PutExtra(); IOClient client = new IOClient(); //对转码后的文件进行使用saveas参数自定义命名,也可以不指定,文件会默认命名并保存在当前空间。 fileName = fileName.Split('.')[0] + ".mp3"; string urlbase64 = Base64URLSafe.Encode(_bucket + ":" + fileName); //一般指文件要上传到的目标存储空间(Bucket)。若为“Bucket”, //表示限定只能传到该Bucket(仅限于新增文件);若为”Bucket:Key”,表示限定特定的文件,可修改该文件。 policy.Scope = _bucket + ":" + fileName; // 可选。 若非0, 即使Scope为 Bucket:Key 的形式也是insert only. policy.InsertOnly = 0; // "|"竖线前是你要转换格式的命令;竖线后是转换完成后,文件的命名和存储的空间的名称! policy.PersistentOps = "avthumb/mp3/ab/128k/ar/44100/acodec/libmp3lame|saveas/" + urlbase64; //规定文件要在那个“工厂”进行改装,也就是队列名称! //policy.PersistentPipeline = "LittleBai"; //音视频转码持久化完成后,七牛的服务器会向用户发送处理结果通知。这里指定的url就是用于接收通知的接口。 //设置了`persistentOps`,则需要同时设置此字段 policy.PersistentNotifyUrl = "http://wwwtest.rupeng.cn:9090/upload/uploadFile"; string upToken = policy.Token(); var putRet = await client.PutAsync(upToken, fileName, stream, extra); return(putRet.StatusCode == HttpStatusCode.OK ? $"{Config.API_HOST}/{putRet.key}" : null); }
/// <summary> /// </summary> /// <param name="op"></param> /// <param name="scope"></param> /// <returns></returns> private async Task <CallRet> op(FileHandle op, EntryPath scope) { string url = string.Format("{0}/{1}/{2}", Config.RS_HOST, OPS[(int)op], Base64URLSafe.Encode(scope.URI)); return(await Call(url)); }
private async Task <CallRet> opFetch(FileHandle op, string fromUrl, EntryPath entryPath) { string url = string.Format("{0}/{1}/{2}/to/{3}", Config.PREFETCH_HOST, OPS[(int)op], Base64URLSafe.Encode(fromUrl), Base64URLSafe.Encode(entryPath.URI)); return(await Call(url)); }
/// <summary> /// </summary> /// <param name="op"></param> /// <param name="pair"></param> /// <returns></returns> private async Task <CallRet> op2(FileHandle op, EntryPathPair pair) { string url = string.Format("{0}/{1}/{2}/{3}", Config.RS_HOST, OPS[(int)op], Base64URLSafe.Encode(pair.URISrc), Base64URLSafe.Encode(pair.URIDest)); return(await Call(url)); }
/// <summary> /// </summary> /// <param name="op"></param> /// <param name="pair"></param> /// <param name="force"></param> /// <returns></returns> private CallRet op2(FileHandle op, EntryPathPair pair, bool force) { string url = string.Format("{0}/{1}/{2}/{3}/force/{4}", Config.RS_HOST, OPS[(int)op], Base64URLSafe.Encode(pair.URISrc), Base64URLSafe.Encode(pair.URIDest), force); return(Call(url)); }
private CallRet opFetch(FileHandle op, string fromUrl, EntryPath entryPath) { string url = string.Format("{0}/{1}/{2}/to/{3}", Config.RS_HOST, OPS[(int)op], Base64URLSafe.Encode(fromUrl), Base64URLSafe.Encode(entryPath.URI)); return(Call(url)); }
/// <summary> /// 获取一元批操作http request Body /// </summary> /// <param name="opName">操作名</param> /// <param name="keys">操作对象keys</param> /// <returns>Request Body</returns> private string getBatchOp_1(FileHandle op, EntryPath[] keys) { if (keys.Length < 1) { return(string.Empty); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < keys.Length - 1; i++) { string item = string.Format("op=/{0}/{1}&", OPS[(int)op], Base64URLSafe.Encode(keys[i].URI)); sb.Append(item); } string litem = string.Format("op=/{0}/{1}", OPS[(int)op], Base64URLSafe.Encode(keys[keys.Length - 1].URI)); return(sb.Append(litem).ToString()); }
public dynamic PictureCallBack(JObject postData) { string type = postData.Value <string>("BusinessType"); string fileKey = postData.Value <string>("key"); string imgPara = postData.Value <string>("imgPara"); int userId = postData.Value <int>("userId"); string thumbKey = fileKey; if (!string.IsNullOrEmpty(imgPara)) { thumbKey = type + "_" + Guid.NewGuid().ToString("N") + ".jpg"; string thumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + thumbKey); string thumbsaveas = "|saveas/" + thumbencodedEntryURI; string imgFops = imgPara + thumbsaveas; Pfop pfop = new Pfop(); string pileline = GetPipeline(); PfopDo(pfop, publicBucket, fileKey, imgFops, pileline, thumbKey, userId); } if (type == "pic") { var user = _userRepository.GetEntity(ConditionEqualId(userId)); DeleteQiniuImageByKey(user.Picture); user.Picture = thumbKey; _userRepository.UpdateEntity(user); } else if (type == "album") { UserSpecial us = this._userSpecialRepository.GetEntity(ConditionEqualId(userId)); if (us != null) { us.Image = thumbKey; this._userSpecialRepository.UpdateEntity(us); } } return(new { key = thumbKey }); }
/// <summary> /// SignRequest /// </summary> /// <param name="request"></param> /// <param name="body"></param> /// <returns></returns> public string SignRequest(System.Net.HttpWebRequest request, byte[] body) { Uri u = request.Address; using (HMACSHA1 hmac = new HMACSHA1(secretKey)) { string pathAndQuery = request.Address.PathAndQuery; byte[] pathAndQueryBytes = Config.Encoding.GetBytes(pathAndQuery); using (MemoryStream buffer = new MemoryStream()) { buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length); buffer.WriteByte((byte)'\n'); if (body.Length > 0) { buffer.Write(body, 0, body.Length); } byte[] digest = hmac.ComputeHash(buffer.ToArray()); string digestBase64 = Base64URLSafe.Encode(digest); return(this.accessKey + ":" + digestBase64); } } }
private dynamic CoverCallBack(JObject postData) { string type = postData.Value <string>("BusinessType"); string fileKey = postData.Value <string>("key"); string imgPara = postData.Value <string>("imgPara"); if (string.IsNullOrEmpty(imgPara)) { return(new { key = fileKey }); } string guidName = Guid.NewGuid().ToString("N") + ".jpg"; string thumbKey = type + "_" + guidName; string thumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + thumbKey); string thumbsaveas = "|saveas/" + thumbencodedEntryURI; string pileline = GetPipeline(); string imgFops = imgPara + thumbsaveas; Pfop pfop = new Pfop(); PfopDo(pfop, publicBucket, fileKey, imgFops, pileline, thumbKey, 0); string smallthumbKey = type + "_small_" + guidName; string smallthumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + smallthumbKey); string smallThumbsaveas = "|saveas/" + smallthumbencodedEntryURI; string smallImgPara = GetSmallImageMogr2(imgPara); string samllImgFops = smallImgPara + smallThumbsaveas; pileline = GetPipeline(); PfopDo(pfop, publicBucket, fileKey, samllImgFops, pileline, smallthumbKey, 0); return(new { bigKey = thumbKey, smallKey = smallthumbKey }); }
/// <summary> /// /// </summary> /// <param name="op"></param> /// <param name="keys"></param> /// <param name="force"></param> /// <returns></returns> private string getBatchOp_2(FileHandle op, EntryPathPair[] keys, bool force) { if (keys.Length < 1) { return(string.Empty); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < keys.Length - 1; i++) { string item = string.Format("op=/{0}/{1}/{2}/force/{3}/&", OPS[(int)op], Base64URLSafe.Encode(keys[i].URISrc), Base64URLSafe.Encode(keys[i].URIDest), force); sb.Append(item); } string litem = string.Format("op=/{0}/{1}/{2}/force/{3}", OPS[(int)op], Base64URLSafe.Encode(keys[keys.Length - 1].URISrc), Base64URLSafe.Encode(keys[keys.Length - 1].URIDest), force); return(sb.Append(litem).ToString()); }
/// <summary> /// SignWithData /// </summary> /// <param name="b"></param> /// <returns></returns> public string SignWithData(byte[] b) { string data = Base64URLSafe.Encode(b); return(string.Format("{0}:{1}:{2}", this.accessKey, _sign(Config.Encoding.GetBytes(data)), data)); }