Consume REST service from OE11.5

Posted by heinota on 04-May-2016 08:54

In OE11.5 is new Net.pl library and it gives to us possibility to make REST call from OE client. But if i try to replace my curl call

curl -X POST -F "file=@picture.png" http://localhost/test/mytest

with OE call, than it files.

Looks like file content is not moving to server. 
To same server I am able to make POST request from OE, but only without ContentType=Multipart/data.

Probably it is my fault, but can anybody show some lights to me?!

Posted by Peter Judge on 04-May-2016 09:32

You are posting content with a (real) mime type of application/pdf.
 
To use multipart, you need use the OpenEdge.Net.MultipartEntity type and its child OpenEdge.Net.MessagePart types.
 
Something along the lines of
assign oEntity = new MultipartEntity()
      oEntity:Boundary = guid
      
       oResp:Entity      = oEntity
       oResp:ContentType = 'multipart/form-data':u
      
       oPart = new MessagePart('image/png':u, oPic)
      
       oHeader = HttpHeaderBuilder:Build('Content-Disposition':u)
                    :Value(substitute('form-data; name="fileContents"; filename=&1':u, quoter(cFilename)))
                    :Header.
 
oEntity:AddPart(oPart).
oPart:Headers:Put(oHeader).
               
 
And then pass the multipart entity to the Post() call. The default is multipart/mixed but you can override that in the Post(<url>, <entity>, <content-type>)
 
hth
 
 

All Replies

Posted by Peter Judge on 04-May-2016 08:56

What's the replacement code?
 

Posted by heinota on 04-May-2016 09:18

copy-lob from file 'document.pdf' to mDocument.

oInputEntity = new Memptr(mDocument).

oRequest = RequestBuilder :Post('http://httpbin.org/post', oInputEntity) :ContentType('multipart/data') :AcceptJson() :Request.

Posted by Peter Judge on 04-May-2016 09:32

You are posting content with a (real) mime type of application/pdf.
 
To use multipart, you need use the OpenEdge.Net.MultipartEntity type and its child OpenEdge.Net.MessagePart types.
 
Something along the lines of
assign oEntity = new MultipartEntity()
      oEntity:Boundary = guid
      
       oResp:Entity      = oEntity
       oResp:ContentType = 'multipart/form-data':u
      
       oPart = new MessagePart('image/png':u, oPic)
      
       oHeader = HttpHeaderBuilder:Build('Content-Disposition':u)
                    :Value(substitute('form-data; name="fileContents"; filename=&1':u, quoter(cFilename)))
                    :Header.
 
oEntity:AddPart(oPart).
oPart:Headers:Put(oHeader).
               
 
And then pass the multipart entity to the Post() call. The default is multipart/mixed but you can override that in the Post(<url>, <entity>, <content-type>)
 
hth
 
 

Posted by Peter Judge on 04-May-2016 09:35

We have had internal conversations about the utility of doing  something like cURL's –F option or webspeed's get-field() where you just set a value and don't care whether it's a form-field or a multipart part or a query string.
 
I'm interested to hear your (all of you) thoughts on this; where and how it's useful.
 

Posted by heinota on 04-May-2016 09:39

OpenEdge.Net.MultipartEntity is part of OE11.6,

I assume, that Multipart messages is impossible to handle with OE11.5 ?

Posted by Peter Judge on 04-May-2016 09:44

Not without basically porting that code.
 

Posted by heinota on 04-May-2016 11:14

We have lot of attachment to documents, what we must store as binary files and idea is to store those files to mongodb as gridfs.  For that there is REST service called restheart. And for that service, if you store with gridfs structure,  everything must have ContentType Multipart/data.   This service is actually quite clever and is able to add real ContentType by himself. So, if I want those binaries back, then they are with correct ContentType.

This thread is closed