2012-10-10 10 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.DownloadBinaryContent नामक एक सहायक कार्य है अंदर Tridion.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' endpoint में विशेषताओं निम्न में से आकार बढ़ाने के लिए आवश्यकता हो सकती है: - maxBufferSize = "+१०७३७४१८२४ "maxBufferPoolSize =" 1073741824 "maxReceivedMessageSize =" 1073741824 "। डिफ़ॉल्ट रूप से उनके पास "65536" –

+0

के रूप में मान है, आपको उचित फ़ाइलपैथ स्ट्रिंग फ़ाइल प्राप्त करने के लिए इस कोड का उपयोग करने की आवश्यकता हो सकती है = "डी: \\ MyTempLocation \\" + Path.GetFileName (multimediaComponent.BinaryContent.Filename); –

संबंधित मुद्दे