10 Replies Latest reply on Oct 10, 2013 5:44 AM by Madhu Garimilla

    Does Teiid REST service support a Blob Input?

    Madhu Garimilla Newbie

      Hi,

       

      I am trying to upload a file to my Teiid REST service which is backed by a virtual procedure. I have defined the input type as blob. Inside the procedure i am trying to make a call to another UDF which takes this blob input and reads the stream. Does Teiid supports a Blob type input in REST service? Does it handle automatic type conversion if i am writing the file to the OutputStream of the HttpUrlConnection object like below?


      String userPassword =  "user:user";

      String encoding = new BASE64Encoder().encode(userPassword.getBytes());

       

      HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();

      connection.setRequestProperty("Authorization", "Basic " + encoding);

      connection.setRequestProperty("Content-Type", "multipart/form-data");

      connection.setRequestMethod("POST");

      connection.setDoOutput(true);

       

      FileInputStream in = new FileInputStream( new File("C:\\SampleWeb.war") );

      OutputStream out = connection.getOutputStream();

      byte[] data = new byte[ 4096 ];

      int bytesRead = 0;

      while(( bytesRead = in.read( data )) != -1 ){

      out.write(data, 0, bytesRead );

      out.flush();

      }

      and here is my model definition inside the vdb

       

      <model name="deploy" type ="VIRTUAL">

               <metadata type="DDL"><![CDATA[

                  SET NAMESPACE 'http://teiid.org/rest' AS REST;

                  CREATE VIRTUAL PROCEDURE g1Table(IN p1 blob) RETURNS TABLE (xml_out boolean) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'POST', "REST:URI" '')

                  AS

                  BEGIN

                      SELECT testmodel.upload(p1) AS xml_out FROM (SELECT 1) as T;

                  END

                  ]]> </metadata>

          </model>