/// <summary> /// [异步async]数据处理 /// </summary> /// <param name="bucket">空间</param> /// <param name="key">空间文件的key</param> /// <param name="fops">操作(命令参数)</param> /// <param name="pipeline">私有队列</param> /// <param name="notifyUrl">通知url</param> /// <param name="force">forece参数</param> /// <returns>pfop操作返回结果,正确返回结果包含persistentId</returns> public async Task <PfopResult> PfopAsync(string bucket, string key, string fops, string pipeline, string notifyUrl, bool force) { PfopResult result = new PfopResult(); try { string pfopUrl = Config.ZONE.ApiHost + "/pfop/"; StringBuilder sb = new StringBuilder(); sb.AppendFormat("bucket={0}&key={1}&fops={2}", bucket, key, StringHelper.UrlEncode(fops)); if (!string.IsNullOrEmpty(notifyUrl)) { sb.AppendFormat("¬ifyURL={0}", notifyUrl); } if (force) { sb.Append("&force=1"); } if (!string.IsNullOrEmpty(pipeline)) { sb.AppendFormat("&pipeline={0}", pipeline); } byte[] data = Encoding.UTF8.GetBytes(sb.ToString()); string token = auth.CreateManageToken(pfopUrl, data); HttpResult hr = await httpManager.PostFormAsync(pfopUrl, data, token); result.Shadow(hr); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("[{0}] pfop Error: ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); Exception e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.RefCode = (int)HttpCode.USER_EXCEPTION; result.RefText += sb.ToString(); } return(result); }
//private void init() //{ // using (StreamReader sr = new StreamReader("Template/JsonFormat.html")) // { // prefopResultTemplate = sr.ReadToEnd(); // } //} private void PfopButton_Click(object sender, RoutedEventArgs e) { string bucket = this.BucketTextBox.Text.Trim(); string key = this.KeyTextBox.Text.Trim(); string fops = this.FopsTextBox.Text.Trim(); if (bucket.Length == 0 || key.Length == 0 || fops.Length == 0) { return; } #region FIX_PFOP_ZONE_CONFIG try { Config.AutoZone(AppSettings.Default.ACCESS_KEY, bucket, false); this.TextBox_PrefopResultText.Clear(); } catch (Exception ex) { this.TextBox_PfopResultText.Text = "配置出错,请检查您的输入(如密钥/scope/bucket等)\r\n" + ex.Message; return; } #endregion FIX_PFOP_ZONE_CONFIG string pipeline = this.PipelineTextBox.Text.Trim(); bool force = this.ForceCheckBox.IsChecked.Value; string notifyURL = this.NotifyURLTextBox.Text.Trim(); Task.Factory.StartNew(() => { Mac mac = new Mac(AppSettings.Default.ACCESS_KEY, AppSettings.Default.SECRET_KEY); OperationManager ox = new OperationManager(mac); PfopResult pfopResult = ox.Pfop(bucket, key, fops.Split(';'), pipeline, notifyURL, force); Dispatcher.BeginInvoke((Action)(() => { if (pfopResult.PersistentId != null) { this.PersistentIdTextBox.Text = pfopResult.PersistentId; } this.TextBox_PfopResultText.Text = pfopResult.Text; this.TextBox_PfopResultString.Text = pfopResult.ToString(); })); }); }
public void PfopTest() { string saveMp4Entry = Base64.UrlSafeBase64Encode(Bucket + ":avthumb_test_target.mp4"); string saveJpgEntry = Base64.UrlSafeBase64Encode(Bucket + ":vframe_test_target.jpg"); string avthumbMp4Fop = "avthumb/mp4|saveas/" + saveMp4Entry; string vframeJpgFop = "vframe/jpg/offset/1|saveas/" + saveJpgEntry; string fops = string.Join(";", new string[] { avthumbMp4Fop, vframeJpgFop }); Mac mac = new Mac(AccessKey, SecretKey); Config config = new Config(); OperationManager manager = new OperationManager(mac, config); string pipeline = "sdktest"; string notifyUrl = "http://api.example.com/qiniu/pfop/notify"; string key = "qiniu.mp4"; bool force = true; PfopResult pfopRet = manager.Pfop(Bucket, key, fops, pipeline, notifyUrl, force); if (pfopRet.Code != (int)HttpCode.OK) { Assert.Fail("pfop error: " + pfopRet.ToString()); } Console.WriteLine(pfopRet.PersistentId); }
public static void pfopAndSave() { string bucket = "BUCKET"; string key = "FILE"; string pipeline = "MEDIAPROC_PIPELINE"; string notifyUrl = "NOTIFY_URL"; bool force = false; string saveAsUri = StringUtils.urlSafeBase64Encode("<SAVEAS_BUCKET>:<SAVEAS_KEY>"); string fops = "<FOPS>" + "|saveas/" + saveAsUri; Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey); Pfop px = new Pfop(mac); PfopResult result = px.pfop(bucket, key, fops, pipeline, notifyUrl, force); System.Console.WriteLine(result.Response); // 稍后可以根据PersistentId查询处理进度/结果 string persistentId = result.PersistentId; Prefop pz = new Prefop(persistentId); PrefopResult zr = pz.prefop(); System.Console.WriteLine(zr.Response); }