I have a difficulty of upload file(e.g. Upload.txt) and JSON data in Jmeter.
Request in View Result Tree
POST http://localhost:8080/xxxx/custom/uploaddocument
POST data:
--jmeter_is_great
Content-Type: application/json; charset=UTF-8
{
"Document": {
"documentName": "TEST.txt",
"fullPath": "Test",
"priority": "M",
"referenceNo": "Ref12345",
"descrption": "Testfile",
"userDef1": "",
"userDef2": "",
"userDef3": "",
"userDef4": "",
"userDef5": "",
"userDef6": "",
"userDef7": "",
"userDef8": "",
"userDef9": "",
"userDef10": "",
"profile": {
"id": -2,
"index": [{
"id": -7,
"value": "Signature",
"type": "D"
}]
},
"ACL": {
"isInherit": false,
"permission": [{
"permissionType": "U",
"userID": 10001,
"groupID": "",
"roleID": "",
"permissionString": "ROPKFIAENTCMDHZVWGLUSB",
"mustFlag": false
}]
}
}
}
--jmeter_is_great
Content-Type: text-plain
THIS IS TESTING FILE CONTENT
--jmeter_is_great--
[no cookies]
Request Headers:
Connection: keep-alive
Content-Length: 876
Content-Type: multipart/related; boundary=jmeter_is_great
POST http://localhost:8080/xxxx/custom/uploaddocument
POST data:
--jmeter_is_great
Content-Type: application/json; charset=UTF-8
{
"Document": {
"documentName": "TEST.txt",
"fullPath": "Test",
"priority": "M",
"referenceNo": "Ref12345",
"descrption": "Testfile",
"userDef1": "",
"userDef2": "",
"userDef3": "",
"userDef4": "",
"userDef5": "",
"userDef6": "",
"userDef7": "",
"userDef8": "",
"userDef9": "",
"userDef10": "",
"profile": {
"id": -2,
"index": [{
"id": -7,
"value": "Signature",
"type": "D"
}]
},
"ACL": {
"isInherit": false,
"permission": [{
"permissionType": "U",
"userID": 10001,
"groupID": "",
"roleID": "",
"permissionString": "ROPKFIAENTCMDHZVWGLUSB",
"mustFlag": false
}]
}
}
}
--jmeter_is_great
Content-Type: text-plain
THIS IS TESTING FILE CONTENT
--jmeter_is_great--
[no cookies]
Request Headers:
Connection: keep-alive
Content-Length: 876
Content-Type: multipart/related; boundary=jmeter_is_great
Response Data
HTTP Status 415 - Unsupported Media Type
Actually, There is a part JSON inside the Document as below:
"content": {
"binary": [80, 97, 114, 97, 68, 77, 32, 84, 69, 83, 84, 32, 102, 105, 108, 101]
}
I have tried request header as follow and then send the whole JSON with "Content" to api:
[HTTP header] Authorization: YXBpYWRtaW46cGFzc3dvcmQ= Content-Type: application/json
However, HTTP 415 response error also be thrown.
Some article with simular issue I have read: Testing REST API File Uploads in JMeter
Look forward for any insight!
Your
Authorization
header seems to be malformed, to wit:A
Basic YXBpYWRtaW46cGFzc3dvcmQ=
Be aware that the better way of bypassing basic HTTP authentication in JMeter is using HTTP Authorization Manager configured like:
http://localhost:8080/xxxx/
apiadmin
password
Your
Content-Type
header is also not correct, you're using wrongboundary
, i.e. in the HTTP Header Manager you haveandytest
and in request body there isjmeter_is_great
and they must match.Assuming above 2 points I think I should warn you that when you're building a request manually any violation of the protocol standard (even extra or missing empty line or a character in lower case) will ruin your request
The referred article assumes using Google Drive API for demo purposes, your application might work differently so you may have to reconsider the whole approach. Try recording your file upload (make sure to copy
TEST.txt
file to JMeter's "bin" folder) using HTTP(S) Test Script Recorder to see how does generated request look like as you might be going in a wrong direction.