File upload using postman without FILE option

Could you please tell me how to upload file without USING File option. I would like to know how I can upload file by following below approach.

From Body - Form data - Type as Text approach
How I can upload file using Body - raw - Json file type
I do not want to use File > Choose File option. I would like to execute through newman and using File > Choose file option it is failing.

I tried to use below approach but it is giving 404 as response.
Body - Raw–>
{
“uploadType”: “ORDER”,
“headerIncluded”:“false”,
“file”:“C:/Users/b3badm/Desktop/SIndoora/FileImport_ValidProducts.txt”
}

Hi @Avdhesh752! You’ll want to check out this blog post :star2:

Hi @claire, is there any way to set the src value from Postman before exporting a collection? Because having to manually edit the collection after each export is a bit annoying.

Hi @jakub.danek! At the moment I don’t believe there is a way to do that, however that makes sense as something we can look into improving - if you have a free moment, we’d love for you to post this in #feature-requests!

  1. Place the files you want to upload in a location.

    Say, I want to upload below two json files from C:\here

    prod.json
    str.json

  2. Create a csv data file ( file.csv ) and place the file names you want to upload as shown below

Files

  1. In your Pre-request script, add set a variable as shown below

pm.environment.set(“filepath”,data._filepath);

  1. Open your collection.json file and you will find the below formdata where you have selected the file location as shown below

“method”: “POST”,
“header”: ,
“body”: {
“mode”: “formdata”,
“formdata”: [
{
“key”: “File”,
“type”: “file”,
“src”: “/C:/here/prod.json”
}

here, modify “src”: “/C:/here/prod.json” to “src”: “{{filepath}}”

  1. Now navigate to the path where you have the files and want to upload. So, in my case I navigated to C:\here and launched cmd from here and executed below command.

newman run --insecure <collection_path>\Products.postman_collection.json -d \file.csv -r htmlextra --reporter-htmlextra-export “<Report_path>\Fileupload.html” --reporter-htmlextra-title “<Report_Name>”

Now my test will run with two iteration as shown below

Iteration1 - you will find the Request body as

{
“File”: “prod.json”
}

Iteration2 - you will find the Request body as

{
“File”: “str.json”
}

Hope, this solution helps us in not selecting a static file and upload all the desired files from selected location