*This is a technical verification article that is not yet known if it can be put into actual use.
There is a rare problem in using SAP Build Apps. That is that SAP Build Apps does not support multipart/form-data format communication. Although this format has been requested less and less recently, it is still in use, so I thought it might be possible to use it and tried to implement it.
Current SAP Build Apps
Recently, the existing REST API Direct Integration has been replaced by universal REST API integration. I personally think that the HTTP Method is fixed for each action such as Select/Create, but compared to REST API Direct Integration, where it was easy to give arguments, there are some things that make me think, “Hmmm…” However, since the HTTP Method can be specified within an action such as Select/Create, it is no longer the case that “Select is used to insert data,” which is a good thing. However, since the HTTP Method can be specified within Select/Create and other actions, it is no longer the case that “Select is used to insert data”, which is a good thing.
HTTP Header and BODY can be manipulated to some extent manually. It would have been nice to be able to choose to send data in multipart/form-data format here, but unfortunately it is not an option.
Brief description of the format multipart/form-data
You should read the RFC specification for this, but here is a “super” simple explanation
Specify “multipart/form-data; boundary=<boundary string>” as Content-Type in Header.In the BODY, specify the following
–<boundary string>
Content-Disposition: form-data; name=”<Field name>”
<Field value>
–<boundary string>
Content-Disposition: form-data; name=”<Field name>”
<Field value>
–<boundary string>–
The boundary string must be preceded by “–” and followed by “–” at the end.The same string as the BOUNDARY string must not appear in this entire sentence.Use CR+LF for line feed code.A single line break should be inserted between the Content-Disposition and the value of the field.
are available. (Of course there are others! Be sure to check the RFC specifications!)
The key point is “The same string as the boundary string must not appear in this entire sentence”. When data is submitted from a browser using an HTML form, this process is done automatically and a boundary string that does not appear in the data is automatically created, but this time you must do it yourself. In particular, this multipart/form-data format can be used to upload file data. You will need to be careful in this case.
How to submit data in multipart/form-data format in SAP Build Apps?
The following is an example. It is based on the motif of submitting the following HTML form. The destination is https://httpbin.org/post, which is a useful service for this kind of situation.
<form action=”https://httpbin.org/post” method=”post”>
<input type=”text” name=”Field1″>
<input type=”text” name=”Field2″>
</form>
1. Integration settings
Use the Universal REST API Integraion.
Set the two text items that are boundary and form input items as Additional Input.
Use Create as the method, making sure POST is set as the Request Method.
Create “Content-Type” as Request Headers.
Value should be set as follows so that the Boundary set for Additional Input is used.
“multipart/form-data; boundary=” + query.additionalInputs.boundary
This is the key : Request body mapper setting.
“–“+query.additionalInputs.boundary + “rn” + “Content-Disposition: form-data; name=”Field1″rnrn”+query.additionalInputs.TextField1+ “rn–” + query.additionalInputs.boundary + “rn” + “Content-Disposition: form-data; name=”Field2″rnrn”+query.additionalInputs.TextField2+ “rn–” + query.additionalInputs.boundary +”–”
You can get a general idea of what this actually looks like from the Exsample results in the screenshot. The point is that the line breaks are done with CR+LF (=rn).
If you understand this formula, you will be able to handle any form.
Enter appropriate values in the test and run it.
As mentioned above, boundary is a delimiter in the data set in the body, so it must not duplicate the data entered in the form. (I use a random keyboard clattering.)
It seems that https://httpbin.org/post recognized this as form data.
2. Logic building
When actually incorporating this into the logic, let’s say the screen is constructed as follows
Set the following as the logic for the button.
Assign GUID to Boundary for now.
*As mentioned above, it is necessary to check if there is any problem using GUIDs. I think you need to check if this generated GUID value is not included in the value entered in the form, and if it is found to be included, you need to generate the GUID value again and check again …. If it is found to contain a GUID value, the logic should be to generate the GUID value again and check it again.
“Create Record” assigns boundary and form values as parameters.
OK, Let’s try.
Set a value on the form and run it.
The value was recognized as a form value = Send this data as “multipart/form-data”.
Not a very cool way to do it, but for now I was able to send data in multipart/form-data format with SAP Build Apps. I hope this will be of some help.
*This is a technical verification article that is not yet known if it can be put into actual use.There is a rare problem in using SAP Build Apps. That is that SAP Build Apps does not support multipart/form-data format communication. Although this format has been requested less and less recently, it is still in use, so I thought it might be possible to use it and tried to implement it.Current SAP Build AppsRecently, the existing REST API Direct Integration has been replaced by universal REST API integration. I personally think that the HTTP Method is fixed for each action such as Select/Create, but compared to REST API Direct Integration, where it was easy to give arguments, there are some things that make me think, “Hmmm…” However, since the HTTP Method can be specified within an action such as Select/Create, it is no longer the case that “Select is used to insert data,” which is a good thing. However, since the HTTP Method can be specified within Select/Create and other actions, it is no longer the case that “Select is used to insert data”, which is a good thing.HTTP Header and BODY can be manipulated to some extent manually. It would have been nice to be able to choose to send data in multipart/form-data format here, but unfortunately it is not an option.Brief description of the format multipart/form-dataYou should read the RFC specification for this, but here is a “super” simple explanationSpecify “multipart/form-data; boundary=<boundary string>” as Content-Type in Header.In the BODY, specify the following–<boundary string>Content-Disposition: form-data; name=”<Field name>”<Field value>–<boundary string>Content-Disposition: form-data; name=”<Field name>”<Field value>–<boundary string>–The boundary string must be preceded by “–” and followed by “–” at the end.The same string as the BOUNDARY string must not appear in this entire sentence.Use CR+LF for line feed code.A single line break should be inserted between the Content-Disposition and the value of the field.are available. (Of course there are others! Be sure to check the RFC specifications!)The key point is “The same string as the boundary string must not appear in this entire sentence”. When data is submitted from a browser using an HTML form, this process is done automatically and a boundary string that does not appear in the data is automatically created, but this time you must do it yourself. In particular, this multipart/form-data format can be used to upload file data. You will need to be careful in this case.How to submit data in multipart/form-data format in SAP Build Apps?The following is an example. It is based on the motif of submitting the following HTML form. The destination is https://httpbin.org/post, which is a useful service for this kind of situation. <form action=”https://httpbin.org/post” method=”post”>
<input type=”text” name=”Field1″>
<input type=”text” name=”Field2″>
</form> 1. Integration settingsUse the Universal REST API Integraion.Set the two text items that are boundary and form input items as Additional Input.Use Create as the method, making sure POST is set as the Request Method.Create “Content-Type” as Request Headers.Value should be set as follows so that the Boundary set for Additional Input is used. “multipart/form-data; boundary=” + query.additionalInputs.boundary This is the key : Request body mapper setting. “–“+query.additionalInputs.boundary + “rn” + “Content-Disposition: form-data; name=”Field1″rnrn”+query.additionalInputs.TextField1+ “rn–” + query.additionalInputs.boundary + “rn” + “Content-Disposition: form-data; name=”Field2″rnrn”+query.additionalInputs.TextField2+ “rn–” + query.additionalInputs.boundary +”–” You can get a general idea of what this actually looks like from the Exsample results in the screenshot. The point is that the line breaks are done with CR+LF (=rn).If you understand this formula, you will be able to handle any form.Enter appropriate values in the test and run it.As mentioned above, boundary is a delimiter in the data set in the body, so it must not duplicate the data entered in the form. (I use a random keyboard clattering.)It seems that https://httpbin.org/post recognized this as form data.2. Logic buildingWhen actually incorporating this into the logic, let’s say the screen is constructed as followsSet the following as the logic for the button.Assign GUID to Boundary for now.*As mentioned above, it is necessary to check if there is any problem using GUIDs. I think you need to check if this generated GUID value is not included in the value entered in the form, and if it is found to be included, you need to generate the GUID value again and check again …. If it is found to contain a GUID value, the logic should be to generate the GUID value again and check it again.”Create Record” assigns boundary and form values as parameters.OK, Let’s try.Set a value on the form and run it.The value was recognized as a form value = Send this data as “multipart/form-data”. Not a very cool way to do it, but for now I was able to send data in multipart/form-data format with SAP Build Apps. I hope this will be of some help. Read More Technology Blogs by SAP articles
#SAP
#SAPTechnologyblog