gpt4 book ai didi

Tridion 核心服务 如何下载多媒体组件的二进制文件

转载 作者:行者123 更新时间:2023-12-02 18:22:33 26 4
gpt4 key购买 nike

我有一个要求,我需要下载多媒体组件的二进制文件,但是当我访问 BinaryContentData 类公开的属性时,没有属性可以下载图像文件。虽然对于上传文件,Core Service 有一个属性,即 UploadFromFile

有没有办法将二进制文件下载到临时位置。下面是我正在使用的代码:

core_service.ServiceReference1.SessionAwareCoreService2010Client client = new SessionAwareCoreService2010Client(); 
client.ClientCredentials.Windows.ClientCredential.UserName = "myUserName";
client.ClientCredentials.Windows.ClientCredential.Password = "myPassword"; client.Open();
ComponentData component = (ComponentData)client.TryCheckOut(
multimediaComponentURI, new ReadOptions());
BinaryContentData binaryData = component.BinaryContent;

请提出建议。

最佳答案

Tridion.ContentManager.CoreService.Client.dll 中有一个名为 streamDownloadClient.DownloadBinaryContent 的辅助函数可供您使用。

我创建了以下函数,我通常为此目的重用该函数:

private static void CreateBinaryFromMultimediaComponent(string tcm)
{
Tridion.ContentManager.CoreService.Client.StreamDownloadClient streamDownloadClient = new StreamDownloadClient();
SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2011");

ComponentData multimediaComponent = client.Read(tcm, new ReadOptions()) as ComponentData;

// Generate you own file name, and file location
string file = "D:\\MyTempLocation\\" + Path.GetFilename(multimediaComponent.BinaryContent.Filename);;

// Write out the existing file from Tridion
FileStream fs = File.Create(file);
byte[] binaryContent = null;

if (multimediaComponent.BinaryContent.FileSize != -1)
{
Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);
var memoryStream = new MemoryStream();
tempStream.CopyTo(memoryStream);
binaryContent = memoryStream.ToArray();
}

fs.Write(binaryContent, 0, binaryContent.Length);
fs.Close();
}

关于Tridion 核心服务 如何下载多媒体组件的二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12816696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com