Load testing server with http multipart/related request which contains audio content - apachebench

We built a server which handles speech recorded by user using an app. The audio data is sent through http post in real time. The body looks like this:
--BOUNDARY
Content-Disposition: form-data; name="metadata"
Content-Type: application/json; charset="UTF-8"
<JSON FORMATTED METADATA HERE>
--BOUNDARY
Content-Disposition: form-data; name="audio"
Content-Type: application/octet-stream
<AUDIO BYTES HERE>
--BOUNDARY--
Now, I need to do load testing for the server. I am thinking of using ApacheBench and just do consistent uploading requests but I wish to use the same format as above for each request. How could that be setup in AB?

I was able to solve the problem by using the following command:
ab -p test -T "multipart/form-data; boundary=BOUNDARY" -c 1000 -n 1000 -l http://someipaddress.com/
where test is a file containing the post content.

Related

Jmeter post multipart form data with string

I am trying to upload file with string in JMeter. It doesn't work
POST http://localhost:8080/upload
POST data:
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="input"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
{ "name": "John", "country": "US" }
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="file"; filename="sample.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r--
[no cookies]
I got the following error using JMeter
{"code":"ERROR","message":"Required request parameter 'input' for method parameter type String is not present"}
I am able to hit the request using curl or Postman without any issues. Here is my curl request.
curl -i -X POST \
-H "Content-Type:multipart/form-data" \
-F "file=#\"./sample.txt\";type=text/plain;filename=\"sample.txt\"" \
-F "input={ \"name\": \"John\", \"country\": "US" }" \
'http://localhost:8080/upload'
If you're able to execute the request successfully using Postman you should be able to record the request using JMeter's HTTP(S) Test Script Recorder
Start the HTTP(S) Test Script Recorder
Configure Postman to use JMeter as the proxy
Copy the sample.txt file to "bin" folder of your JMeter installation
Run your request in Postman
JMeter will capture the request and generated proper HTTP Request sampler
More information: How to Convert Your Postman API Tests to JMeter for Scaling

How can I send multipart/form-data in JMeter

I want to send request payload as following in JMeter:
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="name"
test
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="description"
testing
------WebKitFormBoundaryeBikRH0JCrgmtTvt
Content-Disposition: form-data; name="configFile"; filename="test.json"
Content-Type: application/json
------WebKitFormBoundaryeBikRH0JCrgmtTvt--
So I tried to add the name and description part in Parameters tab with form-data as Content-type and added file in Files Upload tab in HTTP Request Sampler.
This is what I am getting in Request Body after execution:
POST data:
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="name"
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
test
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="description"
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
testing
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1
Content-Disposition: form-data; name="configFile"; filename="test.json"
Content-Type: application/json
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--t9u984dDyYVtn6R0e8-OiZQyWRv9gk1--
I want to remove this part from the request for name and description part
Content-Type: form-data; charset=US-ASCII
Content-Transfer-Encoding: 8bit
This is resulting into failure with status code : 415
Need help on this please
If standard multipart HTTP Request generated by JMeter's HTTP Request sampler when you tick Use multipart/form-data box doesn't work for you be aware that you can manually build the HTTP Request by using:
HTTP Header Manager to set Content-Type header containing the boundary
__FileToString() function to load the contents of your .json file into the request body
Check Testing REST API File Uploads in JMeter for more comprehensive explanation and detailed example

Is it possible to send RingCentral SMS / MMS using multipart/form-data?

The OpenAPI spec for the Create SMS Message endpoint includes the following request content types:
consumes:
- application/json
- multipart/mixed
- multipart/form-data
https://netstorage.ringcentral.com/dpw/api-reference/specs/rc-platform.yml?v=2019082420190816-0828
I found the SMS / MMS instructions to include a multipart/mixed example in the API Reference, but don't see any information on using multipart/form-data. I'm specifically interested in sending files.
https://developers.ringcentral.com/api-reference/SMS/createSMSMessage
The same API Reference shows support for both multipart/form-data and multipart/mixed for sending faxes.
https://developers.ringcentral.com/api-reference/Fax/createFaxMessage
Since both APIs send files and metadata so I'm wondering if the SMS API also supports multipart/form-data and, if so, how to send it?
No, it does not appear so.
The example you'd linked for the SMS message uses multipart/mixed to separate the API call itself (which is in turn sent as application/json) from the payload being sent as an MMS (image/png).
The use of multipart/form-data in the fax API is specific to the way that particular metadata is included, but there isn't an equivalent system for SMS/MMS as they both need that particular meta information encoded either as a single JSON document or as the JSON element of a multipart/mixed message.
To send a file, though, multipart/mixed is fine. Your request would then be something like:
POST /restapi/v1.0/account/403391985008/extension/403391985008/sms
Content-Type: multipart/mixed; boundary=Boundary_1_14413901_1361871080888
--Boundary_1_14413901_1361871080888
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"to" :[{"phoneNumber": "+18772004569"},{"phoneNumber": "+18772094569"}],
"text" :"hello",
"from" :{"phoneNumber": "+18882004237"}}
--Boundary_1_14413901_1361871080888
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="filename.zip"
[Some encoded binary stream here ...]
--Boundary_1_14413901_1361871080888--
It'd be up to you to set the file's mime type properly and ensure things are encoded. The key points here are that the message information is encoded in the first JSON component in your multipart message, while the file attached to the MMS is encoded in the second.
multipart/form-data can be sent as shown in the following example:
POST / HTTP/1.1
HOST: platform.ringcentral.com/restapi/v1.0/account/~/extension/~/sms
Authorization: Bearer <MyToken>
Content-Type: multipart/form-data; boundary=12345
--12345
Content-Disposition: form-data; name="to"
+16505550101
--12345
Content-Disposition: form-data; name="to"
+16505550102
--12345
Content-Disposition: form-data; name="from"
+16505550100
--12345
Content-Disposition: form-data; name="text"
Hello World
--12345
Content-Disposition: form-data; name="attachment" filename="picture.jpg"
content of picture.jpg ...
--12345--
This can be done using curl as follows:
curl -XPOST https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/sms \
-H 'Authorization: Bearer <MyToken>' \
-F 'to=+16505550101' \
-F 'to=+16505550102' \
-F 'from=+16505550100' \
-F 'text=Hello World' \
-F 'attachment=#picture.jpg'

Send email with log file as attachment

I am using Hadoop (CDH 5.4.8) to process the unstructured data and after successful processing I want to send a mail notification to the concerned team with log file as attachment.
CDH 5.4.8 Oozie does not support attachment feature in email action. So I want to do this using shell script. Please let me know the best way to do this.
You can easily send an email from within a shell by piping a complete mail message (header and body) into sendmail. This assumes that the host you're doing this is properly configured with a mail transfer agent (e.g. sendmail or postfix) to send email messages.
The easiest way to send email with an attachment is to create a simple template message in your mail user agent (e.g. Thunderbird), and copy its contents as a template with the view source command. Modify that template to suit your needs and place it in the shell script.
Here is an example:
#!/bin/sh
cat <<\EOF |
To: Ramesh <ramesh#example.com>
From: Diomidis Spinellis <dds#aueb.gr>
Subject: Here are your Hadoop results
Message-ID: <5700BF28.2070500#aueb.gr>
Date: Sun, 3 Apr 2016 09:58:48 +0300
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------030303090406090809090501"
This is a multi-part message in MIME format.
--------------030303090406090809090501
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
The attachment contains your Hadoop results.
--------------030303090406090809090501
Content-Type: application/octet-stream;
name="data"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="data"
HviDNR105+2Tr0+0fsx3OyzNueQqPuAXl9IUrafOi7Y=
--------------030303090406090809090501--
EOF
sendmail ramesh#example.com
To configure a fixed message with actual data, replace the parts you want to modify with commands that generate them. (Note the missing backslash from the here document EOF marker.)
#!/bin/sh
cat <<EOF |
To: Ramesh <ramesh#example.com>
From: Diomidis Spinellis <dds#aueb.gr>
Subject: Here are your Hadoop results
Message-ID: <5700BF28.2070500#aueb.gr>
Date: $(date -R)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------030303090406090809090501"
This is a multi-part message in MIME format.
--------------030303090406090809090501
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
The attachment contains your Hadoop results.
--------------030303090406090809090501
Content-Type: application/octet-stream;
name="data"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="data"
$(base64 binary-data-file.dat)
--------------030303090406090809090501--
EOF
sendmail ramesh#example.com

support multipart POST for apachebench?

I want to use apachebench (ab) to test file upload performance.
I have read the manual and can't find a way to achieve my goal.
My goal is try to upload a file by a HTTP Request with POST method and multipart/form-data format.
The ab support "-p POST-FILE", but I only can find the format key=value&key2=value2
What the post data I want to send is
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryuUlX4554LPBjInc5
------WebKitFormBoundaryuUlX4554LPBjInc5
Content-Disposition: form-data; name="file"; filename="411c40d9.jpg"
Content-Type: image/jpeg
XXXXXXXXXXXXXXX (IMAGE DATA)
YYYYYYYYYYYYYYYYYYYYYYYYYYYYY
I googled for a while and can't find any related article or way to achieve that.
I use cURL and it works fine, but I want to do stress testing.
So I need use ab to achieve that goal.
Any suggestions?
This may be very late but might help others who were searching for the same thing...
$ ab -c 5 -n 5 -v 4 -p example_post.txt -T "multipart/form-data; boundary=miuxupsktcqtriloonfbdudrgtawascl" http://yourapplication.local/upload/
Credit to this guy.

Resources