Question
· 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?

Discussion (10)1
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: https://cedocs.intersystems.com/latest/csp/docbook/Doc.View.cls?KEY=EHTTP_preface
 

If you use Cache Web Services and you are building a custom REST-based service, please read:  https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GREST_services

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 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:

https://cedocs.intersystems.com/latest/csp/docbook/Doc.View.cls?KEY=EHTT...

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

https://community.intersystems.com/post/uploading-and-downloading-files-...

https://community.intersystems.com/post/restful-way-data-transfer

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.