Antonia Frixou
Antonia Frixou

Reputation: 1

How to add file in an pre-request script using form data on Postman

I am trying to create a request in the pre-request script using in the form-data and in the body i would like to upload a pdf file from my working directory.

I used the following script and the file is not attached in my script. Can you please help me to identify my problem?

"body":{ 
        "mode": "formdata",
        "formdata": [
            { "key" : "file","value": "X:\\Postman\\files\\test.pdf", "disabled" : false, "description" : {"content" :"", "type" :"file"}},
            { "key" : "text","value": "text", "disabled" : false, "description" : {"content" :"", "type" :"text"}},
            { "key" : "Number","value": "12345686", "disabled" : false, "description" : {"content" :"", "type" :"text"}},
            { "key" : "Text","value": "0011002327", "disabled" : false, "description" : {"content" :"", "type" :"text"}},  
            { "key" : "Date","value": "02/12/2020", "disabled" : false, "description" : {"content" :"", "type" :"text"}}
        ]}  

Upvotes: 0

Views: 4152

Answers (2)

Mark Đạt
Mark Đạt

Reputation: 1

This is solution:

pm.request.body.update({
     mode: "formdata",
     formdata: [
       { key: "name", type: "text", value: "File 1"},
       { key: "file", type: "file", src: "<Your path>"}
     ]
});

Upvotes: 0

krishna k maurya
krishna k maurya

Reputation: 47

In case of file, KEY name should be src instead of value

eg- "src": "X:\\Postman\\files\\test.pdf"

otherwise it will treated as a text not as file path

kindly refer screenshot for the same

Upvotes: 0

Related Questions