Nael Marwan
Nael Marwan

Reputation: 1038

Uploading files using Karate REST API tool

I'm trying to upload images on specific slack channel using Karate but no luck, I tried multiple times with different steps but still have 200 response and the image is not displayed in the channel. Tried to post text content and successfully found the text on the channel.

Bellow are 2 of my tries following the Karate documentation:

@post
Feature: Post images

Background: 
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}

Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename: 
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200

OR

Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200

Am I missing something? Tried the same examples found in Karate demo GitHub repository of uploading pdf and jpg but no luck.

Note: worked using Slack API UI.

Upvotes: 1

Views: 3134

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

You seem to be mixing up things, there is no need for a request body when you are using multipart. Your headers / params look off. Also based on the doc here, the name of the file-upload field is file. Try this:

Scenario: upload image
Given url 'https://slack.com/api/files.upload'
And multipart file file = { read: 'thumb.jpg', filename: 
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
When method post
Then status 200

If this doesn't work, take the help of someone who can understand how to interpret the Slack API doc. Or get a Postman test working, then you'll easily figure out what you missed.

Upvotes: 2

Related Questions