# POSTing a random file in a scenario

**URL:** <https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262>\
**Category:** Gatling (Open-Source)\
**Created:** [February 8, 2013, 9:50pm UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262 "2013-02-08T21:50:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Coarr](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Coarr](https://community.gatling.io/u/Matt_Coarr)\
**Post date:** [February 8, 2013, 9:50pm UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/1 "2013-02-08T21:50:49Z")

</div>

My gatling script creates a set of users (5) and then each user iterates over a loop 20 times. The contents of the loop issues a single http request.

The http request is a POST request to a rest web service.

I have a directory with 1000 request bodies. How do I grab one of those files to post (e.g. the parameter to the fileBody() method call)?

I’ve tried the following using feed(), but it just tries to load a file that that includes the expression literally (not replacing it with a value from the csv file) – e.g. [http://myhost.mycompany.com:8080/my-rest-service](http://myhost.mycompany.com:8080/my-rest-service)

My csv file listing all my data files looks like this:

filename  
file123.txt  
file456.txt

Essentially, I do three things:

- load the csv file with the list of all my files containing http post contents:

- val fileList = csv(“file\_listing\_\_separated\_smaller.csv”).concurrentQueue- call feed() with this fileList variable as a parameter

- .feed(fileList)- call the fileBody() method

- .fileBody("${filename}")

Attempted script contents:

val httpConf = httpConfig  
.baseURL(“[http://myhost.mycompany.com:8080](http://myhost.mycompany.com:8080)”)  
.acceptHeader("_/_")  
.userAgentHeader(“curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5”)  
.warmUp(“[http://myhost.mycompany.com:8080](http://myhost.mycompany.com:8080)”)

val headers\_1 = Map(  
“Content-Type” → “”“text/plain”"",  
“Expect” → “”“100-continue”"",  
“Proxy-Connection” → “”“Keep-Alive”""  
)

val fileList = csv(“file\_listing.csv”).concurrentQueue

val scn = scenario(“Scenario Name”)  
.feed(fileList)  
.repeat(20)  
{  
exec(  
http(“request\_1”)  
.post("/my-rest-service")  
.headers(headers\_1)  
.fileBody("${filename}")  
)  
.pause(3)  
}

setUp(scn.users(5).protocolConfig(httpConf))

Thanks!  
Matt

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 9, 2013, 7:43am UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/2 "2013-02-09T07:43:47Z")

</div>

Hi,

Bad luck: that’s not currently possible, the template location is static.  
Could you fill an issue, please?

We should be able to have it for 1.4.3 coming next week.

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 9, 2013, 11:27am UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/3 "2013-02-09T11:27:01Z")

</div>

I actually implemented it on the master/v2 branch.  
This part has gone under major refactoring, so backporting is not straightforward.  
Would it be possible for you to use a 2.0.0-SNAPSHOT?

You can grab one on Cloudbees:  
[https://forge.cloudbees.com/a/gatling/](https://forge.cloudbees.com/a/gatling/)

Available methods are now:

- body for passing a String
- rawFileBody
- fileBody for passing a template file that uses Gatling EL
- sspBody for passing a SSP template
- byteArrayBody  
Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Matt\_Coarr](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Coarr](https://community.gatling.io/u/Matt_Coarr)\
**Post date:** [February 11, 2013, 5:01am UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/4 "2013-02-11T05:01:58Z")

</div>

Perfect Stéphane!! Thanks so much! Yes, I’ll pull and use the 2.0.0-SNAPSHOT!

Glad I asked!

Thanks for your help!  
Matt

---

<div class="post-metadata">

**Author:** ![Matt\_Coarr](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Coarr](https://community.gatling.io/u/Matt_Coarr)\
**Post date:** [February 11, 2013, 2:56pm UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/5 "2013-02-11T14:56:23Z")

</div>

Do you have instructions on how to use the snapshot version? I see that I can grab the individual jars for each gatling module from the maven repo, but I don’t see a complete download .tar.gz.

I also tried grabbing the trunk code from git and running “mvn package” (which also build the individual module jars).

Is there a command to produce the bundle .tar.gz?

Or can I just take my 1.4.1 binary directory and delete all the gatling\*.jar files and replace them with the 2.0-SNAPSHOT versions? (I suspect some of the other dependencies might need to be updated too).

Thanks for your help!

Matt

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 11, 2013, 4:13pm UTC](https://community.gatling.io/t/posting-a-random-file-in-a-scenario/262/6 "2013-02-11T16:13:44Z")

</div>

The bundles are in the repo too:  
[http://repository-gatling.forge.cloudbees.com/snapshot/com/excilys/ebi/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT](http://repository-gatling.forge.cloudbees.com/snapshot/com/excilys/ebi/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT)

You’ll probably have to delete your gatling-recorder.ini, it might not be compatible.

Cheers,

Stéphane
