二开案例.WebApi上传附件字段
接口说明:
在物料上加了2个附件字段,一个单附件,一个多附件,ID分别是F_UNW_Attachment_83g、F_UNW_Attachments_qtr
K3CloudApiClient apiClient; private string url = "http://localhost/k3cloud/"; private string dbid = "65b8.......d06"; private string userName = "demo"; private string password = "888888"; private int lcid = 2052; void Main() { apiClient = new K3CloudApiClient(url); var isLoginOk = apiClient.Login(dbid, userName, password, lcid); if (!isLoginOk) return; var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); //上传附件 var uploadResultJson1 = apiClient.UploadFile(javaScriptSerializer.Serialize(new { FileName = "text1.txt", IsLast = true, SendByte = Convert.ToBase64String(Encoding.UTF8.GetBytes("content1 " + DateTime.Now)) })); var fileId1 = (javaScriptSerializer.Deserialize<Dictionary<string, object>>(uploadResultJson1)["Result"] as Dictionary<string, object>)["FileId"].ToString(); var uploadResultJson2 = apiClient.UploadFile(javaScriptSerializer.Serialize(new { FileName = "text2.txt", IsLast = true, SendByte = Convert.ToBase64String(Encoding.UTF8.GetBytes("content2 " + DateTime.Now)) })); var fileId2 = (javaScriptSerializer.Deserialize<Dictionary<string, object>>(uploadResultJson2)["Result"] as Dictionary<string, object>)["FileId"].ToString(); //获取附件信息 var fileInfos = apiClient.ExecuteBillQuery(javaScriptSerializer.Serialize(new { FormId = "BOS_FileServerFileInfo", FieldKeys = "FFileId,FFileName,FFileSize", FilterString = $"ffileid in ('{fileId1}','{fileId2}')" })) .Select(r => new { fileId = r[0], fileName = r[1], fileSize = r[2] }).ToList(); //保存附件 var FNumber = "A" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); var FName = FNumber; var saveResult = apiClient.Save("BD_MATERIAL", javaScriptSerializer.Serialize( new { NeedReturnFields = new string[] { "F_UNW_Attachment_83g", "F_UNW_Attachments_qtr" }, Model = new { FNumber, FName, //单附件字段 F_UNW_Attachment_83g = fileInfos[0].fileId, //多附件字段 F_UNW_Attachments_qtr = fileInfos.Select(fi => new { ServerFileName = fi.fileId, FileName = fi.fileName, FileBytesLength = fi.fileSize }) } })); //修改附件 var billId = (javaScriptSerializer.Deserialize<Dictionary<string, object>>(saveResult)["Result"] as Dictionary<string, object>)["Id"].ToString(); var modifyResult = apiClient.Save("BD_MATERIAL", javaScriptSerializer.Serialize( new { NeedUpDateFields = new string[] { "F_UNW_Attachment_83g", "F_UNW_Attachments_qtr" }, NeedReturnFields = new string[] { "FID", "FNumber", "F_UNW_Attachment_83g", "F_UNW_Attachments_qtr" }, Model = new { FMATERIALID = billId, //单附件字段 F_UNW_Attachment_83g = fileInfos[1].fileId, //多附件字段 F_UNW_Attachments_qtr = new object[]{ new { ServerFileName = fileInfos[1].fileId, FileName = fileInfos[1].fileName, FileBytesLength = fileInfos[1].fileSize }} } })); }
WebApi报文:
上传附件1 http://[IP]/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UploadFile.common.kdsvc {"FileName":"text1.txt","IsLast":true,"SendByte":"Y29udGVudDEgMjAyNC81LzIyIDE0OjE5OjAy"} 上传结果: {"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":0},"FileId":"0e6df974470d4bc29e697e5b6c6c20ab","Message":""}} 上传附件2 http://[IP]/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UploadFile.common.kdsvc {"FileName":"text2.txt","IsLast":true,"SendByte":"Y29udGVudDIgMjAyNC81LzIyIDE0OjE5OjAy"} 上传结果: {"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":0},"FileId":"647a195dd6dd4f20bbc655985c51a50c","Message":""}} 获取附件信息 http://[IP]/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc {"FormId":"BOS_FileServerFileInfo","FieldKeys":"FFileId,FFileName,FFileSize","FilterString":"ffileid in (\u00270e6df974470d4bc29e697e5b6c6c20ab\u0027,\u0027647a195dd6dd4f20bbc655985c51a50c\u0027)"} 获取附件信息结果 [["0e6df974470d4bc29e697e5b6c6c20ab","text1.txt",27],["647a195dd6dd4f20bbc655985c51a50c","text2.txt",27]] 保存单据: {"NeedReturnFields":["F_UNW_Attachment_83g","F_UNW_Attachments_qtr"],"Model":{"FNumber":"AX20240522141902286","FName":"AX20240522141902286","F_UNW_Attachment_83g":"0e6df974470d4bc29e697e5b6c6c20ab","F_UNW_Attachments_qtr":[{"ServerFileName":"0e6df974470d4bc29e697e5b6c6c20ab","FileName":"text1.txt","FileBytesLength":27,"FileLength":27},{"ServerFileName":"647a195dd6dd4f20bbc655985c51a50c","FileName":"text2.txt","FileBytesLength":27,"FileLength":27}],"FAttachment":"0e6df974470d4bc29e697e5b6c6c20ab"}} 保存结果: {"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":152058,"Number":"AX20240522141902286","DIndex":0}],"SuccessMessages":[],"MsgCode":0},"Id":152058,"Number":"AX20240522141902286","NeedReturnData":[{"FMATERIALID":152058,"F_UNW_Attachment_83g":"0e6df974470d4bc29e697e5b6c6c20ab","F_UNW_Attachments_qtr":"[{\"ServerFileName\":\"0e6df974470d4bc29e697e5b6c6c20ab\",\"FileName\":\"text1.txt\",\"FileBytesLength\":27,\"FileLength\":27},{\"ServerFileName\":\"647a195dd6dd4f20bbc655985c51a50c\",\"FileName\":\"text2.txt\",\"FileBytesLength\":27,\"FileLength\":27}]"}]}}
二开案例.WebApi上传附件字段
接口说明:webapi附件上传接口说明 (kingdee.com)在物料上加了2个附件字段,一个单附件,一个多附件,ID分别是F_UNW_Attachment_83g、F_UN...
点击下载文档
本文2024-09-16 18:27:25发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22263.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章