[Upload File] How to upload file when the header chunked file !

I face an issue with upload file when request limit the file only 1mb. It’s mean if i upload a file with 1mb, just create one request. If I upload a file 3mb then request create 3 request to divide the file. etc…

This is my script for upload file, it work fine when image < 1mb:

val UploadFilesInCls =
exec(session => {
val fileResourcePath = Paths.get(baseResourscesPath).toString;
val someFile = new File(fileResourcePath)
session.set(“fileResourcePath”, fileResourcePath)
})

def UploadFiles(baseUrl: String, csrfToken: String)
= http(“Upload file on community page”)
.post(baseUrl + “/file/file/upload”)
.headers(headerSocialCollaborationUploadFile)
.header(“X-CSRF-Token”, csrfToken)
.formUpload(“files[]”, “${fileResourcePath}/${fileName}”)

And the request header when i upload more than 1mb:

Request URL: https://mysite.xyz/file/file/upload
Request Method: POST
Status Code: 200
content-disposition: attachment; filename=“image_1mb_4.jpg”
content-length: 900192
content-range: bytes 0-899999/2182674
content-type: multipart/form-data; boundary=----WebKitFormBoundaryq7EKfTV0MbgSpVNr

Request URL: https://mysite.xyz/file/file/upload
Request Method: POST
Status Code: 200
content-disposition: attachment; filename=“image_1mb_4.jpg”
content-length: 900192
content-range: bytes 900000-1799999/2182674
content-type: multipart/form-data; boundary=----WebKitFormBoundaryo4s0XFtwBp4JNA5U

Request URL: https://mysite.xyz/file/file/upload
Request Method: POST
Status Code: 200
content-disposition: attachment; filename=“image_1mb_4.jpg”
content-length: 382866
content-range: bytes 1800000-2182673/2182674
content-type: multipart/form-data; boundary=----WebKitFormBoundary6gG7Uv4WMa4zp6WN

I try using .header(“Transfer-Encoding”, “chunked”) seem as it do not work, please advice.

You have to split the file yourself and send as many requests as parts and manually set the content-range header.

You mean, using the scala language split the file then send it in many request as a parts.

You mean, using the scala language split the file

Not necessarily. The most efficient way would be to prepare the chunks upstream prior to running the actual load test. You can do that in whatever technology suits you.

then send it in many requests as parts.

Yes

I had split the image file to 3 parts, and send it in to 3 requests. All request response is OK, but the body is empty instead return some information (id, name,…).

My script is:
def UploadFiles1(baseUrl: String, csrfToken: String)
= http(“Upload 1”)
.post(baseUrl + “/file/file/upload”)
.headers(headerSocialCollaborationUploadFile1)
.header(“X-CSRF-Token”, csrfToken)
.body(RawFileBody(“C:/projects/MOE/07_SPT/cx-opal-gatling-Release_2.2/user-files/resources/test0104/0001_request.dat”))

def UploadFiles2(baseUrl: String, csrfToken: String)
= http(“Upload 2”)
.post(baseUrl + “/file/file/upload”)
.headers(headerSocialCollaborationUploadFile2)
.header(“X-CSRF-Token”, csrfToken)
.body(RawFileBody(“C:/projects/MOE/07_SPT/cx-opal-gatling-Release_2.2/user-files/resources/test0104/0002_request.dat”))

def UploadFiles3(baseUrl: String, csrfToken: String)
= http(“Upload 3”)
.post(baseUrl + “/file/file/upload”)
.headers(headerSocialCollaborationUploadFile3)
.header(“X-CSRF-Token”, csrfToken)
.body(RawFileBody(“C:/projects/MOE/07_SPT/cx-opal-gatling-Release_2.2/user-files/resources/test0104/0003_request.dat”))

val UploadFiles =
.exec(BP13_SocialCollaborationLib.UploadFiles1("${base-url}"))
.pause(1)
.exec(BP13_SocialCollaborationLib.UploadFiles2( “${base-url}” ))
.pause(3)
.exec(BP13_SocialCollaborationLib.UploadFiles3( “${base-url}” ))
.pause(3)

And the response return for 3 request:

HTTP response:
status=
200 OK
headers=
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: nginx
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-TRACE-VIRTUAL-PATH: csl
X-TRACE-VIRTUAL-URI: /file/file/upload
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Xss-Protection: 1; mode=block
X-Cache: Miss from cloudfront
Via: 1.1 abaf9410e0cb5238ad0ea84e120ca7c0.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: HKG60-C1
X-Amz-Cf-Id: WXDWTUZkFa7qMEkWtEs9c_WBFPDitQzfHKENIS1oqQGb0qSlr3Jqfg==

body=
{“files”:[]}

My concern is how to join a file after i sent it as multipart. So it doesn’t return the body infor? Is that right !

Compare the payloads both Gatling and your actual client send.
That’s something you can do, unless you’re looking for consulting.