Rest API (V15) multipart/form-data file upload with JWT not supported?

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
marcel.heij
Posts: 15
Joined: Thu Aug 15, 2019 4:35 pm

Rest API (V15) multipart/form-data file upload with JWT not supported?

Post by marcel.heij »

I am trying to create a srvroutine for file upload via multipart/form-data in combination with JWT security. However it seems the TryBind method does not support multipart/form-data. Is that correct? Does somebody have an example of a file upload API with JWT security?
marcel.heij
Posts: 15
Joined: Thu Aug 15, 2019 4:35 pm

Re: Rest API (V15) multipart/form-data file upload with JWT not supported?

Post by marcel.heij »

Well, my question is still stands, but I do have a workaround without the TryBind method unfortunately:

* ================================================================================= *
Srvroutine Name(UploadFile) Desc('Save a Blob on de server as a file') Response(*HTTP #Context)
Define Field(#TokenFromHeader) Type(*NVARCHAR)

* Get the HTTP header with the name 'Authorization' and assign to the just defined field
#Context.Request.Headers.TryGetString("Authorization" #TokenFromHeader)

* Take the #TokenFromHeader and trim off the 'Bearer ' string at the beginning to just pass the token string to the TryVerifyToken method
If (#HSnnn.TryVerifyToken( #TokenFromHeader.LeftTrim("Bearer "), #jwt, "YourSecret" ))

* Get the multipart/form-data variables including the file itself
#S_ClientAgreementID := #Context.Request.Content.FormVariables<"ClientAgreementID">.Value
#FileType := #Context.Request.Content.FormVariables<"FiletypeCode">.Value
#DF_ELFNAM := #Context.Request.Content.FormVariables<"File">.FileName

<< rest of the code >>
Endif
Endroutine
* ================================================================================= *
This seems to work, but is it the right way to do it? Does the TryBind method need more development from Lansa or do I miss something?
Post Reply