Rest API (V15) multipart/form-data file upload with JWT not supported?
-
marcel.heij
- Posts: 15
- Joined: Thu Aug 15, 2019 4:35 pm
Rest API (V15) multipart/form-data file upload with JWT not supported?
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?
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?
* ================================================================================= *
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?