2012-10-10 47 views
6

我有我需要下载一个多媒体组件的二进制文件,但是当我访问暴露BinaryContentData类的属性则没有物业下载一个图像文件要求的二进制文件。虽然上传文件,核心服务有一个属性,即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; 

请建议。

回答

5

有一个叫streamDownloadClient.DownloadBinaryContentTridion.ContentManager.CoreService.Client.dll一个辅助函数,你可以使用。

我已经创建了下面的函数,我通常重用为目的:

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(); 
} 
+0

对于使用上面的代码,你可能还需要增加以下在“streamDownload_basicHttp_2010”端点属性的大小: - MAXBUFFERSIZE =“1073741824 “maxBufferPoolSize =” 1073741824" maxReceivedMessageSize = “1073741824”。默认情况下,他们有值为“65536” –

+0

您可能需要使用此代码来获得适当的文件路径字符串文件=“d:\\ \\ MyTempLocation” + Path.GetFileName(multimediaComponent.BinaryContent.Filename); –

相关问题