public DfopResult dfop(string fop, byte[] data) { DfopResult dfopResult = new DfopResult(); HttpFormFile dfopData = HttpFormFile.NewFileFromBytes("netFx.png", "application/octet-stream", data); string dfopUrl = string.Format("{0}/dfop?fop={1}", API_HOST, fop); string token = Auth.createManageToken(dfopUrl, null, mac); Dictionary <string, string> dfopHeaders = new Dictionary <string, string>(); dfopHeaders.Add("Authorization", token); CompletionHandler dfopCompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { if (respInfo.isOk()) { dfopResult = StringUtils.jsonDecode <DfopResult>(response); } dfopResult.ResponseInfo = respInfo; dfopResult.Response = response; }); mHttpManager.postMultipartDataRaw(dfopUrl, dfopHeaders, dfopData, null, dfopCompletionHandler); return(dfopResult); }
/// <summary> /// 以表单方式上传字节数据 /// </summary> /// <param name="data">字节数据</param> /// <param name="key">保存在七牛的文件名</param> /// <param name="token">上传凭证</param> /// <param name="uploadOptions">上传可选设置</param> /// <param name="upCompletionHandler">上传完成结果处理器</param> public void uploadData(byte[] data, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { HttpFormFile fFile = HttpFormFile.NewFileFromBytes(key, null, data); // 此处未设置FormFile.ContentType,稍后设置(在upload中已设置) @fengyh 2016-08-17 15:03 upload(fFile, key, token, uploadOptions, upCompletionHandler); }