How to capture file upload Content from dsp page

Thank you @John_Carter4 it’s working after adding those declarations

@John_Carter4

I am getting the below line at end of the content. How can I get rid of this line.

------WebKitFormBoundarylqskd07qksdjl–

Hmm, me too.
It might be a bug I will need to look into this.
regards,
John.

1 Like

@John_Carter4 How to pass input parameters (text, select, etc) along with file uploaded content to flow service via dsp when using post method in form?

Hi @Warrior_S - you would need to use multipart handling. I might have a sample I can share here. I will look at the samples and attached here.

if the additional data is limited, then you could always use query params or headers. Otherwise you need to send multiple pars as @srikanth.prathipati1803 indicated.
regards,
John.

1 Like

@srikanth.prathipati1803 thanks, can you please share the example so that I can use.

@John_Carter4 thanks. Can you please share if you have any sample snippet for query parameters or headers.

Do you mean example code to generate this ?
or example such as a request ?
e.g.

MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="XXXXboundary text"

This is a multipart message in MIME format.

--XXXXboundary text
Content-Type: text/plain

this is the body text

--XXXXboundary text
Content-Type: text/plain;
Content-Disposition: attachment;
        filename="test.txt"

this is the attachment text

--XXXXboundary text--

or

POST / HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __atuvc=34%7C7; permanent=0; _gitlab_session=226ad8a0be43681acf38c2fab9497240; __profilin=p%3Dt; request_method=GET
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
Content-Length: 554

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"

text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

-----------------------------9051914041544843365972754266--

the command curl is capable of sending multiple files via mime attachments e.g.

$ curl -F "text=default" -F "file1=@a.html" -F "file1=@a.txt" localhost:5555/invoke/jc.test:receive

John.

Forgot to add that for a DSP page all you need to do is add more form inputs and the request will automatically be submitted in multiple parts as below.

------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data;

name="name" text 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data; 

name="description" description 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data; 
name="fileName"; 
filename="test.txt" 
Content-Type: text/plain 

test file 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC--

Interestingly each input value gets its own part and not not grouped as form data, perhaps there is a way of changing that.
John.

TryIt.zip (96.6 KB)
Do refer to TryIt.v3.services.pub:processFile @Warrior_S
Each part needs to be handled separately
image

1 Like

each one will be in a separate contentPart with a Content-Disposition called form-data
e.g.

------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data;

name="name" text 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data; 

name="description" description 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC 
Content-Disposition: form-data; 
name="fileName"; 
filename="test.txt" 
Content-Type: text/plain 

test file 
------WebKitFormBoundaryFLBl4kVBtl3F5yWC--

Use pub.mime:getBodyPartContent for each one.

regards,
John.

@srikanth.prathipati1803 I have used your code and finally it worked. Below services are key part before createMimeData in order to capture the content correctly.

pub.flow:getTransportInfo
pub.mime:mergeHeaderAndBody

@John_Carter4 thank you for your consistent help.

1 Like

Glad to know it worked, lot of consultants does not know to process multi-part data in webMethods.

1 Like

hey @srikanth.prathipati1803 i can’t install your TryIt package because it need wmGRPC, do you have the package so i can download?

TryIt.zip (96.6 KB)
I have attached the package without the dependency.

hello @John_Carter4 and @srikanth.prathipati1803 is there any flow example to convert IData objects to multipart-formdata? i am quite confused to add each contents to the body part

Hi,

I might have one sample, I will check my archives and get back again.

So i want to generate this kind of message from IData, while this screenshot was made by request from postman

i want to transform this Json request that are transformed to IData when sent to the IS

{
"partnerReferenceNo":"1231231111",
"additionalInfo":{"channel":"MSM","deviceId":"VAMS"}
}

but i try to construct mimeData and addBodyPart the MimeData generated was wrong

"mimeData": {
        "headers": {
            "name": "JsonData"
        },
        "part": {
            "headers": {
                "1231231111": "1231231111",
                "content-transfer-encoding": "7bit",
                "content-type": "text/plain"
            },
            "part": {
                "smime": "false",
                "headers": {
                    "content-transfer-encoding": "7bit"
                },
                "content": "java.io.ByteArrayInputStream@41d5c6ff"
            }
        }

while i want generate message similar to this

POST / HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __atuvc=34%7C7; permanent=0; _gitlab_session=226ad8a0be43681acf38c2fab9497240; __profilin=p%3Dt; request_method=GET
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
Content-Length: 554

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"

text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

-----------------------------9051914041544843365972754266--

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.