二开案例.WebApi上传、删除附件原创
金蝶云社区-齐111
齐111
32人赞赏了该文章 224次浏览 未经作者许可,禁止转载编辑于2024年11月26日 11:28:45
K3CloudApiClient apiClient;
private string url = "xxxx/k3cloud/";
private string dbid = "664....a9";
private string userName = "demo";
private string password = "888888";
private int lcid = 2052;

void Main()
{
	var apiClient = new K3CloudApiClient(url);
	apiClient.Login(dbid, userName, password, lcid);

	var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

	var billNo = "1003";    //单据编号
	var interId = 100003;   //单据内码
	var formId = "UNW_testfj";  //单据标识

	var fileBytes = File.ReadAllBytes(@"D:\temp\test.png");
	var uploadJson = javaScriptSerializer.Serialize(new
	{
		FileName = "test.png",
		IsLast = true,
		SendByte = Convert.ToBase64String(fileBytes),
		InterId = interId,
		BillNo = billNo,
		FormId = formId,
	});
	Console.WriteLine("上传附件报文:" + uploadJson);

	//上传附件
	var uploadResultJson = apiClient.AttachmentUpload(uploadJson);
	Console.WriteLine($"上传结果:{uploadResultJson}");


	var getFileInfoRequestJson = javaScriptSerializer.Serialize(new
	{
		FormId = "BOS_Attachment",
		FieldKeys = "FFileId,FId",
		FilterString = $"FBillNo='{billNo}' and FBillType='{formId}'"
	});

	Console.WriteLine("获取附件信息报文:" + getFileInfoRequestJson);

	//获取附件信息
	var fileInfos = apiClient.ExecuteBillQuery(getFileInfoRequestJson)
	.Select(r => new { FFileId = r[0], FId = r[1] }).ToList();

	Console.WriteLine("获取到的附件信息:" + javaScriptSerializer.Serialize(fileInfos));

	//删除附件
	var deleteJson = javaScriptSerializer.Serialize(new
	{
		Ids = string.Join(",", fileInfos.Select(f => f.FId).ToArray())
	});
	var deleteResult = apiClient.Delete("BOS_Attachment", deleteJson);
	Console.WriteLine("删除报文:" + deleteJson);
	Console.WriteLine("删除结果:" + deleteResult);

}


程序输出:

上传附件报文:{"FileName":"test.png","IsLast":true,"SendByte":"iVBORw0KGgoAAAANSUhETgOkBAACAU4DpAQAAgFOA6QEAAIBTgOkBAACAU4DpAQAAgFOA6QEAAIAT8Hj8A4eRzRV1xreiAAAAAElFTkSuQmCC","InterId":100003,"BillNo":"1003","FormId":"UNW_testfj"}
上传结果:{"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":162194,"Number":null,"DIndex":0}],"SuccessMessages":[],"MsgCode":0},"FileId":"c0c08fcfa6fb40cb9e8bc9f57b5b6572","Message":""}}
获取附件信息报文:{"FormId":"BOS_Attachment","FieldKeys":"FFileId,FId","FilterString":"FBillNo=\u00271003\u0027 and FBillType=\u0027UNW_testfj\u0027"}
获取到的附件信息:[{"FFileId":"c0c08fcfa6fb40cb9e8bc9f57b5b6572","FId":162194}]
删除报文:{"Ids":"162194"}
删除结果:{"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":162194,"Number":null,"DIndex":0}],"SuccessMessages":[],"MsgCode":0}}}

上传后:

image.png

删除后:

image.png

图标赞 32
32人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!