Written by

Software Architect at Visum
Article Yuri Marx · Nov 4, 2020 1m read

Extract a file from a multipart form or api using ReadMIMEMessage

If you want get a file from a multipart API or html form request use ReadMIMEMessage, see my sample.

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/automl11.png"
    Set reader = ##class(%Net.MIMEReader).%New()
    //Set message = ##class(%Net.MIMEPart).%New()
    Do reader.OpenStream(pInput)
    Set tsc2 = reader.ReadMIMEMessage(.message)
    Do message.ClearHeaders()
    Do file.CopyFromAndSave(message.Body
    
    Set tSC=$$$OK
    Set pOutput = "success" 
    Quit tSC
}

 

}