YURI MARX GOMES · Nov 2, 2020

Html Form Upload and EnsLib.HTTP.InboundAdapter sample

How Can I do to receive and read an uploaded file from a HTML form or REST API formdata into a Custom EnsLib.HTTP.InboundAdapter?

1 2 10 106
Log in or sign up to continue


Is your use case such that someone is posting data to your Server? If you use Ensemble, you probably benefit by reading:

If you use Cache Web Services and you are building a custom REST-based service, please read:

Basically, it sounds like you need to build REST-based Web Service that can receive http requests with attachments.  I assume that you already have a commercial Web Server (like Apache) where you can authenticate requests to your system and set up SSL certification if needed.

I will use Ensenble, but official documentation has only simple sample to get an id value only. I need a upload file sample.

I am seeing this in EnsLib.HPPT.InboundAdapter:

/// Set this property from onInit() in your Service class to make the adapter parse form variables from the form body in case of a form POST
Property ParseBodyFormVars As %Boolean;

So you just need to implement the OnInit() method as described here:

I realize that the docs provide very little... just looked through them myself. So I found more posts that you might find helpful:

I think the first post may be all you need... just put the upload part into the OnProcessnput() of your custom business service. You can also see similar code in the 2nd article, when you scroll to where it talks about form data.

Good luck!

Thanks @Vitaly Furman by detailed instructions, but I need a sample where I receive a file uploaded by user using an REST API with formdata mode and get objectscript reference to this file. In your samples, the first refers to the documentation, thats don't have file upload sample and in the second, the sample is about a custom cache project, not about ensemble.

Here's how you can create a REST API and call production from it.

Inside your REST handler you can access request body via:

  • %request.Data - get access to request body as one binary or character stream
  • %request.GetMimeData("MimeDataName") - get access to request form data value as binary or character stream

Here's a simple fileserver in ObjectScript.

Thanks! So ensenble don't have suport to multipart right?

It does, but %CSP.REST is a preferable way of handling REST Requests.

As you can easily call production from REST just do it whenever the need arises.

It is because this business service will be a PEX service, so it will are depends with an external rest service, and it limits your reusability. In my service I have the file yet, but I don't know how  to extract file inside the globalbinary variable. But if did not have alternative, I will create de REST service.

IIRC you're doing Tesseract OCR - in that case I would recommend the following architecture:

  • %CSP.REST handler to get requests
  • empty BS to proxy requests
  • BO (PEX or otherwise) to interact with Tesseract  (in goes binary stream or a file name out goes text stream)