httprunner上传文件multipart/form-data


Content-Type = multipart/form-data
#上传文件


Rquest Payload

    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="sysCode"

 
 

    S04
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="subSysCode"

 
 

    S0401
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="fileType"

 
 

    image
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="filePermission"

 
 

    PUBLIC
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="file"; filename="2.jpg"
    Content-Type: image/jpeg

    ------WebKitFormBoundarymAyGmnyhpf3UBdec--



#
yaml用例 - test: name: 上传文件 request: url: $url/api/add method: POST files: sysCode: [null,'S04'] subSysCode: [null,'S0401'] fileType: [null,'image' ] filePermission: [null,'PUBLIC'] file: ['2.jpg',$file1,'image/jpeg'] extract: - fileId: content.responseBody.fileId validate: - eq: [status_code, 200] - eq: [content.status, SUCCESS] - eq: [content.status, SUCCESS] variables: - filePath: "D:\\Pictures\\2.jpg" - file1: ${get_file($filePath)}

file参数说明:
file = {'name': (<filename>, <file object>,<content type>, <per-part headers>)}

 

#debugtalk.py
# 读取文件内容
def get_file(filePath):
    return open(filePath, "rb")


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM