使用Karate REST API工具上传文件 [英] Uploading files using Karate REST API tool

查看:155
本文介绍了使用Karate REST API工具上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用空手道在特定的松弛频道上上传图片,但是没有运气,我尝试了不同的步骤多次,但是仍然有200个响应,并且图片未显示在频道中.尝试发布文字内容并成功在频道中找到文字.

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

  @post功能:发布图片背景:*网址'https://slack.com/api/files.upload'* def req_params = {令牌:'xxxxxxx',渠道:'团队',文件名:'来自空手道',漂亮:'1'}场景:上传图片给定路径"api",文件"和参数req_headers而多部分文件myFile = {读取:'thumb.jpg',文件名:'upload-name.jpg',contentType:'image/jpg'}和多部分字段消息=图像上传测试"并要求req_headers方法发布时然后状态200 

OR

 给出路径'files','binary'和参数req_params并要求读取('thumb.jpg')方法发布时然后状态200 

我错过了什么吗?尝试了在空手道演示GitHub存储库中找到的上载pdf和jpg的示例,但是没有运气.

注意:使用Slack API UI可以工作.

解决方案

您似乎正在混淆,使用 multipart 时不需要 request 正文

代码>.您的标题/参数看起来不对.同样基于此处的文档,文件上传字段的名称为文件.试试这个:

 方案:上传图片给定网址'https://slack.com/api/files.upload'并且多部分文件文件= {读取:'thumb.jpg',文件名:'upload-name.jpg',contentType:'image/jpg'}和多部分字段令牌='xxxx-xxxxxxxxx-xxxx'方法发布时然后状态200 

如果这不起作用,请可以理解如何解释Slack API文档的人员帮助.或进行邮递员测试,然后您可以轻松找出错过的地方.

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.

解决方案

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.

这篇关于使用Karate REST API工具上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆