title: Sending a PDF file in a REST Message
body: <p>I am trying figure this out any help appreciated. Thanks in advance</p>
  <p>The service is a file passthrough that picks up a  PDF and then uses the BPL  code below to create the rest wrapper and sends the stream data. I am not grabbing the stream from the inbound correctly,  &quot;request.Stream&quot; or &quot;request.StreamFC&quot; always produces the following  error.</p>
  <p>Here is what is sent and returned in the message..</p>
  <p>request:</p>
  <pre><code>*
  
  &lt;Stream&gt;
      15@%Library.FileCharacterStream
      &lt;/Stream&gt;
      response:
      &lt;Stream&gt;
      Unable to load xml from message: Data at the root level is invalid. Line 1, position 1.
      &lt;/Stream&gt;
  </code></pre>
  <ul>
  <li></li>
  </ul>
  <p>-I think my issue is I am not using the right class by using &quot;%GlobalStreamCharacter&quot;,  Or the raw PDF CDATA inbound I am not handling correctly</p>
  <pre><code>set context.RESTMessage.Stream=##class(%GlobalCharacterStream).%New() 
  </code></pre>
  <p>I have tried using different Stream types...File, Binary....but no luck</p>
  <p>-The general BPL below</p>
  <p>/// BPL Definition
  X</p>
  <pre><code>Data BPL [ XMLNamespace = &quot;http://www.intersystems.com/bpl&quot; ]
      {
      &lt;process language='objectscript' request='Ens.StreamContainer' response='Ens.Response' 
       height='2000' width='2000' &gt;
      &lt;context&gt;
  
      .....
  
      .....
  
      ....
  
      &lt;code name='Create REST Message' xpos='200' ypos='250' &gt;
      &lt;![CDATA[
         set context.RESTMessage=##class(EnsLib.HTTP.GenericMessage).%New()
         set context.RESTMessage.Stream=##class(%GlobalCharacterStream).%New()
         set tSC=context.RESTMessage.Stream.Write(request.StreamFC)
         set tSC=context.RESTMessage.HTTPHeaders.SetAt(&quot;application/xml&quot;,&quot;Content-Type&quot;)
         set tSC=context.RESTMessage.HTTPHeaders.SetAt(context.RESTMessage.Stream.Size,&quot;Content- 
         Length&quot;)
         set tSC=context.RESTMessage.HTTPHeaders.SetAt(&quot;POST&quot;,&quot;HttpRequest&quot;)
      
     
         ]]&gt;
      &lt;/code&gt;
  </code></pre>