二开案例.WebApi上传物料图片原创
4人赞赏了该文章
152次浏览
编辑于2024年10月30日 14:34:02
void Main() { string url = "xxxx"; string dbid = "xxx"; string userName = "xxx"; string password = "xxxx"; int lcid = 2052; K3CloudApiClient apiClient = new K3CloudApiClient(url); var isLoginOk = apiClient.Login(dbid, userName, password, lcid); Console.WriteLine($"登录:{isLoginOk}"); if (!isLoginOk) return; var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); var fileBytes = File.ReadAllBytes(@"D:\temp\test.png"); var uploadJson1 = javaScriptSerializer.Serialize(new { FileName = "test.png", IsLast = true, SendByte = Convert.ToBase64String(fileBytes) }); Console.WriteLine("上传附件报文:" + uploadJson1); //上传附件 var uploadResultJson = apiClient.UploadFile(uploadJson1); Console.WriteLine($"上传结果:{uploadResultJson}"); var fileId = (javaScriptSerializer.Deserialize<Dictionary<string, object>>(uploadResultJson)["Result"] as Dictionary<string, object>)["FileId"].ToString(); Console.WriteLine($"附件fileId:{fileId}"); var formId = "BD_MATERIAL"; var model = new { FmaterialId = "物料内码", FImageFileServer = fileId //fileId赋值给“图片(文件服务器)”字段 }; var saveResult = apiClient.Save(formId, javaScriptSerializer.Serialize(new { Model = model })); Console.WriteLine($"保存结果:{saveResult}"); }
执行结果:
赞 4
4人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读