1

I have a endpoint with a multipart request which takes two files as part of the request parameter. I tried with the below snippet with read and it worked, but my use case is to take content from a file and pass it to the value parameter. Can I pass the content as a file?

The working code if my I try to read the file from directory is

Working feature::

Scenario:
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { read: './oldfile.json', filename: 'oldfile.json'}
And multipart file newfile = { read: './newfile.json', filename: newfile.json'}
When method post
Then status 200

Not working feature::

Scenario:
Given url "http://download-oldfile/oldfile"
When method get
* def oldfile = response
Given url "http://download-newfile/newfile"
When method get
* def newfile = response
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { value: '#(oldfile)', filename: 'oldfile.json'}
And multipart file newfile = { value: '#(newfile)', filename: newfile.json'}
When method post
Then status 200

The contents are printed correctly but api returns error when I use value

Please let me know if I am missing something as part of running with the value keyword in multipart file. Thank you

Nachi K
  • 45
  • 6

2 Answers2

1

Can't think of anything other than try to convert the value to a string:

* string oldfile = response

If still stuck, follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
1

Had the same issue, resolved without needing to save to file by defining a variable holding the JSON object and using set to manipulate its value.

In your case this would look like:

* def temp = {value: '', filename: 'oldfile.json'}
* set temp.value = oldFile
#[...]
And multipart file oldFile = temp