2012-10-10 5 views
6

マルチメディアコンポーネントのバイナリファイルをダウンロードする必要がありますが、BinaryContentDataクラスの公開プロパティにアクセスすると、イメージファイルをダウンロードするプロパティはありません。ファイルをアップロードする場合、コアサービスにはUploadFromFileのプロパティがあります。Tridion core serviceマルチメディアコンポーネントのバイナリファイルをダウンロードする方法

バイナリファイルを一時的な場所にダウンロードする方法はありますか?以下は私が使用しているコードです:

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

あなたが使用することができます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(); 
} 
+0

を、あなたも「streamDownload_basicHttp_2010」エンドポイントの属性を次のサイズを大きくする必要があるかもしれません: - MaxBufferSizeの= "1073741824 "maxBufferPoolSize =" 1073741824 "maxReceivedMessageSize =" 1073741824 "。デフォルトでは、値は "65536" –

+0

です。適切なファイルパス文字列file = "D:\\ MyTempLocation \\" + Path.GetFileName(multimediaComponent.BinaryContent.Filename)を取得するには、このコードを使用する必要があります。 –

関連する問題