使用 Karate REST API 工具上传文件

Uploading files using Karate REST API tool

我正在尝试使用空手道在特定的松弛通道上上传图像,但没有成功,我尝试了多次不同的步骤,但仍然有 200 个响应,并且图像未显示在通道中。 尝试 post 文本内容并成功找到频道上的文本。

以下是我根据空手道文档进行的 2 次尝试:

@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

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

我错过了什么吗?尝试了在空手道演示 GitHub 上传 pdf 和 jpg 的存储库中找到的相同示例,但没有成功。

注意:使用 Slack API UI.

你好像把事情弄混了,当你使用 multipart 时不需要 request body。你的 headers / params 看起来不对。同样基于doc here,file-upload字段的名称是file。试试这个:

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

如果这不起作用,请寻求能够理解如何解释 Slack API 文档的人的帮助。或者让 Postman 测试工作,然后你会很容易地找出你错过了什么。