I would like upload a media file such as image, audio file, etc..
In postman, I can run the API to upload the file, the details in postman please check screenshots as below.


When I transfer postman's request to karate feature, but fail.
My feature file as below.
Feature: test
Background:
* url 'http://example.axm'
Scenario: upload file
Given path 'api/media/save'
And header Authorization = 'token'
And multipart field file = read('coverImage.png')
And multipart field Type = 'image'
When method post
Then status 200
error message
response: MimeType of file uploaded is Invalid.
could you advise how I can implement it by Karate for this upload file call?
In addition to the doc, refer to the demo also: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/upload/upload.feature
Try this.
And multipart file file = { read: 'coverImage.png', filename: 'coverImage.png', contentType: 'image/jpeg' }
And multipart field Type = 'image'
And multipart field File = '14ebbblah'
And multipart field MimeType = 'image/jpeg'
And multipart field Extension = 'jpg'
@ptrthomas
thanks for your reply, I follow the demo and got the passed result.
if the scenario Karate can handle automatically for user, it would be great, so that end user only write the simple such as:
multipart field file = read('1.png');
it is very similar to postman (postman no need to set property contentType: 'image/jpeg' in addition ).
@ansonliao thanks for confirming. I'm not convinced about your suggestion - for example in your case the file extension is png and you want it to be converted to jpeg !?
@ptrthomas
multipart field file = read('1.jpeg');
multipart file file = { read: '1.jpeg', filename: '1.jpeg', contentType: 'image/jpeg' }
by
multipart field file = read('1.jpeg');
From my case, I changed
multipart file file = { read: '1.jpeg', filename: '1.jpeg', contentType: 'image/jpeg' }
to
multipart field file = read('1.jpeg');
the scenario will be fail.
so whether Karate will be possible that even the read statement without contentType value, and Karate will detect the contentType and then append it automatically for end user?
@ansonliao I agree that this will be convenient. but for now, I don't want to maintain a huge list of all possible file-extensions and mappings to mime-types.
@ptrthomas thanks for your reply