Question
TCS
IN
Last activity: 17 May 2017 5:22 EDT
How to pass a file as form data in connect rest post method body
There is a API I am connecting through connect rest post method. I require to browse and select a file from the local machine. This file requires to be passed in the body of the request while calling the connect rest post method.
While trying this out through any rest client (eg. postman) i see in body mentioned as form-data. This accepts a key and file as input. I am able to call the API and perform the functionality.
How can I do the same through pega.
-
Likes (2)
Tyler Stubbs prathyusha manchikatla -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
TCS
IN
Thanks Ashutosh and Paul.
We have implemented the same using multipart form data and type binary. We used the Pega default feature to add an attachment to work object. We created a button in actions tab configured event on click to perform the following in sequence, calling Local Action pyAttachContent, Set Value of .pyAttachmentType to "File", Calling an activity , Refreshing the harness.
In the activity we are opening the attachment through the key pyAttachments(n).pxLinkedRefTo property (Present in pyWorkPage) in a page of class Data-WorkAttach-File (SampleFile). Then creating a page pyRequestAttachmentPage of class Data-ServiceMessage and setting the four parameters
1)pyAttachNames(n) [This contains the parameter to be passed eg. name, file etc.];
2)pyAttachTypes(n) [This contains the content-type eg. application/json etc. ]. This should NOT be set to "multipart/formdata"
3)pyAttachValues(n) [This contains the binary data of the file to be passed] the value is SampleFile.pyAttachStream,
4)pyAttachFileNames(n) [This contains the entire file name with extension] the value is SampleFile.pxAttachName
We call the Connect rest with this page in clipboard and the file gets send along with the request.
Thanks Ashutosh and Paul.
We have implemented the same using multipart form data and type binary. We used the Pega default feature to add an attachment to work object. We created a button in actions tab configured event on click to perform the following in sequence, calling Local Action pyAttachContent, Set Value of .pyAttachmentType to "File", Calling an activity , Refreshing the harness.
In the activity we are opening the attachment through the key pyAttachments(n).pxLinkedRefTo property (Present in pyWorkPage) in a page of class Data-WorkAttach-File (SampleFile). Then creating a page pyRequestAttachmentPage of class Data-ServiceMessage and setting the four parameters
1)pyAttachNames(n) [This contains the parameter to be passed eg. name, file etc.];
2)pyAttachTypes(n) [This contains the content-type eg. application/json etc. ]. This should NOT be set to "multipart/formdata"
3)pyAttachValues(n) [This contains the binary data of the file to be passed] the value is SampleFile.pyAttachStream,
4)pyAttachFileNames(n) [This contains the entire file name with extension] the value is SampleFile.pxAttachName
We call the Connect rest with this page in clipboard and the file gets send along with the request.
In our case we did not want the file to be in work object so deleted the attachment from class Link-Attachment (pyWorkPage.pyAttachments(n).pzInsKey ) and Data-WorkAttach-File (pyWorkPage.pyAttachments(n).pxLinkedRefTo).Then refreshed the data page D_AttachmentList passing the parameter as Work Object pzInsKey.
Thanks...
Pegasystems Inc.
US
This PDN article has good detail on what you are needing.
Key comment :
- When building the outbound message content for a REST, SOAP, SAP, dotNet, or HTTP connector, PRPC looks for a top-level clipboard page named pyRequestAttachmentPage of type Data-ServiceMessage
https://community.pega.com/support/support-articles/unable-send-attachment-connect-rest
DHL
IN
Hi Paul,
Is this scenario works in pega 6.3sp1?
Pegasystems Inc.
AU
It seems that you want to send multipart data in the connect rest call
In general we have four properties to be set on pyRequestAttachmentPage(Data-ServiceMessage)
The generation of multipart request depends on the four properties which is present in Data-ServiceMessage class
1)pyAttachFileNames
2)pyAttachTypes
3)pyAttachValues
4)pyAttachNames
pyAttachname,pyValues is mandatory to be set, pyAttachtype and pyAttachFilename
pyAttachtype generates content-type of the part, if not given falls back to default application/octetstream
pyAttachname generates the content-disposition header where name is the parameter
if pyAttachname option is not given the file name is defaulted to whatever value is specified in attachname
There are two types of "parts" that are supported: binary and text for the "multipart/form-data" content type.
For binary parts, all four parameters are required: name, filename, type and value.
It seems that you want to send multipart data in the connect rest call
In general we have four properties to be set on pyRequestAttachmentPage(Data-ServiceMessage)
The generation of multipart request depends on the four properties which is present in Data-ServiceMessage class
1)pyAttachFileNames
2)pyAttachTypes
3)pyAttachValues
4)pyAttachNames
pyAttachname,pyValues is mandatory to be set, pyAttachtype and pyAttachFilename
pyAttachtype generates content-type of the part, if not given falls back to default application/octetstream
pyAttachname generates the content-disposition header where name is the parameter
if pyAttachname option is not given the file name is defaulted to whatever value is specified in attachname
There are two types of "parts" that are supported: binary and text for the "multipart/form-data" content type.
For binary parts, all four parameters are required: name, filename, type and value.
For string parts, only the name and value are required, while the file name must be blank or null. The type may be specified but, if not, "text/plain" is assumed.
You can take a look at Pega-Int-Storage-Box.D_pxCreateFile, which calls the Pega-Int-Storage-Box.pzCreateFileRequest data transform. This data transform is used to upload an arbitrary file type in one part, along with JSON metadata in a string part.
-
Tyler Stubbs Srinivasan T
Accepted Solution
TCS
IN
Thanks Ashutosh and Paul.
We have implemented the same using multipart form data and type binary. We used the Pega default feature to add an attachment to work object. We created a button in actions tab configured event on click to perform the following in sequence, calling Local Action pyAttachContent, Set Value of .pyAttachmentType to "File", Calling an activity , Refreshing the harness.
In the activity we are opening the attachment through the key pyAttachments(n).pxLinkedRefTo property (Present in pyWorkPage) in a page of class Data-WorkAttach-File (SampleFile). Then creating a page pyRequestAttachmentPage of class Data-ServiceMessage and setting the four parameters
1)pyAttachNames(n) [This contains the parameter to be passed eg. name, file etc.];
2)pyAttachTypes(n) [This contains the content-type eg. application/json etc. ]. This should NOT be set to "multipart/formdata"
3)pyAttachValues(n) [This contains the binary data of the file to be passed] the value is SampleFile.pyAttachStream,
4)pyAttachFileNames(n) [This contains the entire file name with extension] the value is SampleFile.pxAttachName
We call the Connect rest with this page in clipboard and the file gets send along with the request.
Thanks Ashutosh and Paul.
We have implemented the same using multipart form data and type binary. We used the Pega default feature to add an attachment to work object. We created a button in actions tab configured event on click to perform the following in sequence, calling Local Action pyAttachContent, Set Value of .pyAttachmentType to "File", Calling an activity , Refreshing the harness.
In the activity we are opening the attachment through the key pyAttachments(n).pxLinkedRefTo property (Present in pyWorkPage) in a page of class Data-WorkAttach-File (SampleFile). Then creating a page pyRequestAttachmentPage of class Data-ServiceMessage and setting the four parameters
1)pyAttachNames(n) [This contains the parameter to be passed eg. name, file etc.];
2)pyAttachTypes(n) [This contains the content-type eg. application/json etc. ]. This should NOT be set to "multipart/formdata"
3)pyAttachValues(n) [This contains the binary data of the file to be passed] the value is SampleFile.pyAttachStream,
4)pyAttachFileNames(n) [This contains the entire file name with extension] the value is SampleFile.pxAttachName
We call the Connect rest with this page in clipboard and the file gets send along with the request.
In our case we did not want the file to be in work object so deleted the attachment from class Link-Attachment (pyWorkPage.pyAttachments(n).pzInsKey ) and Data-WorkAttach-File (pyWorkPage.pyAttachments(n).pxLinkedRefTo).Then refreshed the data page D_AttachmentList passing the parameter as Work Object pzInsKey.
Thanks...
-
Madan Kumar Prakash Murthy
Virtusa
IN
Hi Samarjeet,
I also have the same requirement. Have to pass file to Connect-Rest rule. Though I set values in pyRequestAttachmentPage, the json request doesnt show the file. I am getting file required error. Could you please help.
Please find the documents attached.
Thanks.
This comment has been branched out as a new node and the new thread can be followed here
-
NagaRajesh Mandava
Pegasystems Inc.
IN
Hello,
Since this post is marked Answered, we have created a new post for you: Have to pass file to Connect-Rest rule but facing the file required error
Please update the new post to continue troubleshooting.
Regards,