Trying to run two chains sequentially, part of first chain runs after the second chain

I’m writing a performance test with the following steps :

  • Upload a file, and from the response save the “fileID” in a separate JSON file to be used later to download the file
  • Download the file by feeding the JSON created in the previous step as RawFileBody as body of the request
    Both these have to be run in a sequence one after the other

Code as follows :

val uploadFile: ChainBuilder = exec(http("Upload a File to be downloaded later")
  .post("/file") // end-point to be load tested
  .header("username", "abc") // user-name header
  .header("password", "xyz") // password header
  .formUpload("file", testFile1MB) // body params ("key" , "path of the file/name")
  .formParamSeq(Seq(("uploadByID", "1"), ("location", "meetings"), ("personID", "0"), (
  "uploadTimeStamp", "2019-01-15 10:01:04.426"), ("md5Hash", md5Hash1Mb))) // other body params ("key", "value")
  .check( // check assertion for status code
  .exec { session =>
     fileGuid = session("guid").as[String].trim
    if (downlGuidJsonFile.exists()) {
    val guidWriter = new PrintWriter(new FileOutputStream(new File(downloadGuidFilePath), true))
    guidWriter.write("{" + "\"" + "uuid" + "\"" + ":" + "\"" + fileGuid + "\"" + "}")