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

**URL:** <https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853>\
**Category:** Gatling (Open-Source)\
**Created:** [October 19, 2020, 4:16pm UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853 "2020-10-19T16:16:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@victor](https://community.gatling.io/u/victor)\
**Post date:** [October 19, 2020, 4:16pm UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/1 "2020-10-19T16:16:22Z")

</div>

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](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](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](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.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [October 19, 2020, 7:18pm UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/2 "2020-10-19T19:18:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![victor](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@victor](https://community.gatling.io/u/victor)\
**Post date:** [October 20, 2020, 2:38am UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/3 "2020-10-20T02:38:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [October 20, 2020, 7:35am UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/4 "2020-10-20T07:35:02Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![victor](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@victor](https://community.gatling.io/u/victor)\
**Post date:** [October 20, 2020, 4:51pm UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/5 "2020-10-20T16:51:33Z")

</div>

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](http://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 !**

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [October 21, 2020, 8:16am UTC](https://community.gatling.io/t/upload-file-how-to-upload-file-when-the-header-chunked-file/5853/6 "2020-10-21T08:16:21Z")

</div>

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