5

I have some Multimedia Components which contain uploaded binary files of multimedia types PDF and MS Word.

Is it possible to read the content of the PDF/DOC from the Multimedia Component using the TOM.NET API?

  • It's not clear how what exactly you wish to do. Are you just looking to read the bytes of the PDF/doc/image? Do you want to do it automatically through code? Where would the code be running (console app, event system, template, etc.)? – Peter Kjaer Dec 8 '14 at 12:17
  • Yeah looking for reading the source of the binary items through the code console app – Doors Dec 8 '14 at 12:20
  • 1
    You shouldn't be using the TOM.NET API in a Console App; use the Core Service API instead. – Rick Pannekoek Dec 11 '14 at 18:27
6

You can get the bytes of the document/image/... that was uploaded to the multimedia component. I believe you can get it using this code

// MMComp contains the multimedia component - you can get this via a call to the  GetObject(tcmuri) function

if (MMComp.BinaryContent != null)
{
    var bytes = MMComp.BinaryContent.GetByteArray();
}

Now, you have the bytes of the uploaded file. Depending on what your application has to do, you'll have to save it as an appropriate file (you can't treat the bytes of a pdf file as it were a png file, or vice versa).

sing the property MMComp.BinaryContent.Filename, you should be able to retrieve the file name of the original uploaded file, and find out if the original file is a pdf, png, gif, or whatever other file type you allow in your Multimedia Schema.

  • 1
    "MMComp.BinaryContent.Filename [...] find out if the original file is a pdf, png, gif" -- Or you could check the Multimedia Type associated with it... – Nuno Linhares Dec 8 '14 at 18:06
  • 2
    Note that the BinaryContent class also has a WriteToStream method, which may be easier to use if all you want to do with the binary data is writing it to a file (or some other stream). That method also prevents loading the entire binary in memory. – Rick Pannekoek Dec 8 '14 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.