4 Replies Latest reply on Oct 17, 2018 2:24 PM by roryg18

    ORDS upload document of any type

    roryg18

      Using 12c.

       

      We're currently defining our endpoints in pl/sql and using pl/sql to parse the request bodies before doing any DML.

       

      One thing we haven't been able to figure out is how to have a request body of binary and then parse that binary appropriately.

       

      First thing we do in the ORDS endpoint source is grab the body;

       

      declare

           l_body blob := :body;

      begin

       

      Specifically, what I need to do is get the file metadata before I add the blob to a table.

      I would like to check the file size and make sure that mime type is what I expect it to be e.g. only allow .png, .jpeg and .doc. Nothing else.

       

      Currently, we're using Ordimage.getProperties to get the metadata for images but have no luck finding something similar that would work for .pdf, .doc, .xls, etc, etc.

       

      We've tried Orddoc but this doesn't appear to work correctly.

       

      Would anyone have any suggestions of how documents (of any type) should be uploaded to ORDS so that they can be parsed and validated accordingly?

        • 1. Re: ORDS upload document of any type
          Kiran Pawar

          Hi roryg18,

          roryg18 wrote:

           

          Using 12c.

           

          We're currently defining our endpoints in pl/sql and using pl/sql to parse the request bodies before doing any DML.

           

          One thing we haven't been able to figure out is how to have a request body of binary and then parse that binary appropriately.

           

          First thing we do in the ORDS endpoint source is grab the body;

           

          declare

          l_body blob := :body;

          begin

           

          Specifically, what I need to do is get the file metadata before I add the blob to a table.

          I would like to check the file size and make sure that mime type is what I expect it to be e.g. only allow .png, .jpeg and .doc. Nothing else.

           

          Currently, we're using Ordimage.getProperties to get the metadata for images but have no luck finding something similar that would work for .pdf, .doc, .xls, etc, etc.

           

          We've tried Orddoc but this doesn't appear to work correctly.

           

          Would anyone have any suggestions of how documents (of any type) should be uploaded to ORDS so that they can be parsed and validated accordingly?

          You can use content_type and content_length HTTP headers to determine the mime type and file size.

          Refer:

           

          Moreover, if yours is a web application, you can do it using javascript at UI level before even submitting the page.

           

          Hope this helps!

           

          Regards,

          Kiran

          • 2. Re: ORDS upload document of any type
            roryg18

            Thanks for the response.

             

            I can't trust what the user manually set. I need to simply pull in a binary body and then extract out the information needed.

            Ordimage works perfectly for images, I need something more generic.

            I'm also keen to know if it's possible to extract out the filename from the blob, I'm thinking that all of this information must contained within it?

            • 3. Re: ORDS upload document of any type
              thatJeffSmith-Oracle

              I've tried, and not found a way to get that working. Disclaimer: i'm probably doing something wrong with Ordimage calls...

               

              Why not have your application set that info when they choose the file, and then include that in your POST? I grab the file name and file type and store it as separate columns in my table, making it very easy to pull out later.

              • 4. Re: ORDS upload document of any type
                roryg18

                Thanks Jeff,

                 

                We were hoping to confirm that what was sent in the request body is actually what we expect it to be and that people aren't spoofing headers i.e. saying this is a .xls file when it's really .pdf file.