[Progress Communities] [Progress OpenEdge ABL] Forum Post: How to POST binary data (application/octet-stream) to a PASOE Rest WebService ?

Status
Not open for further replies.
S

slacroixak

Guest
OE 11.7.5 Trying to achieve a sample REST WebService to upload binary data from an ABL http client Request. On the client side, I prepare a POST request this way: DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO. DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO. DEFINE VARIABLE filemptr AS MEMPTR NO-UNDO. DEFINE VARIABLE oBody AS OpenEdge.Core.Memptr NO-UNDO. COPY-LOB FROM FILE ".\TestPostPictures.zip" TO filemptr NO-CONVERT. oBody = NEW OpenEdge.Core.Memptr(filemptr). oRequest = RequestBuilder:post( ' localhost:8810/.../PostBinSmallFile' , oBody):Request. oRequest:ContentType = "application/octet-stream". oRequest:ContentLength = GET-SIZE(filemptr). oResponse = ClientBuilder:Build():Client:Execute(oRequest). On the AppServer side, I expose a simple REST service with resource POST associated to a class VOID method with one input MEMPTR parameter. Simple Input Mapping from HttpMessage:Body to prmptr (java:byte[] ) @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false"). METHOD PUBLIC VOID PostBinSmallFile (pmptr AS MEMPTR): COPY-LOB FROM pmptr TO FILE "./received.zip" NO-CONVERT. FINALLY: SET-SIZE(pmptr) = 0. END FINALLY. END METHOD. This always results in HTTP Error 415 Unsupported Media Type The AppServer access log says: "POST /AKQRest/rest/AKQRestService/PostBinSmallFile HTTP/1.1" 415 A few articles advise to convert the binary content to text with BASE64-ENCODING, but I really would like to avoid that for performance sake (that service will be used intensively). I've tried the application/zip content type with the same result. The http client is happy to send, but I have not yet found how to define, bind and code the server side. Any hint of piece of doc I may find for that? So far, I know how to GET or PUT json stuff for simple parameters or temp-tables. I am missing how to handle binary data.

Continue reading...
 
Status
Not open for further replies.
Top