Yuri Marx · Nov 3, 2020

Save multipart file upload to a Ens.BusinessService

I created a Custom Business Service to receive a multipart message with a file and I need to save only the file, not all message. How Can I extract only the file from the pInput to save in a File? This is my code:


Class dc.Test.TestService Extends Ens.BusinessService
Parameter ADAPTER = "EnsLib.HTTP.InboundAdapter";
Method OnProcessInput(pInput As %GlobalBinaryStreampOutput As %RegisteredObjectAs %Status
    Set file=##class(%Stream.FileBinary).%New()
    Set file.Filename="/tmp/automl.png"
    Do file.CopyFromAndSave(pInput
    Set tSC=$$$OK
     Set pOutput = "success"
    Quit tSC


This is the content of the pInput:

Content-Disposition: form-data; name="id"; filename="automl.png"
Content-Type: image/png


IHDR  €  8   g±V   sRGB ®Îé   gAMA  ± üa       pHYs  t  tÞfx  ÿ¥IDATx^ìÝ    |Uº'~îÜžIß¡ûO;ssïô0Ž×±½Þ¯c÷qci@DA[h\pAŶQYDÐ JØ! ȶd@XÂK€°„H^’7«ÿ§êœ:uj}

.....(binary content)...




2 127
Discussion (3)1
Log in or sign up to continue

Hi Yuri,
Have a look at this :
Here you will find and example of a multi-part upload on a %CSP.REST class.

To get the stream from the multi part you have to do this ligne 39 to 43 :

    // Get stream
    set stream = %request.GetMimeData("id")
    if ('$IsObject(stream) {
      $$$ThrowOnError($$$ERROR(9200,"no file"))

Where id is the name of you multi-part

To send the stream to a business service :



Where BsName is the name of your business service in the active production of your namespace.
And stream you stream.

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.