title: POST request in Gatling
body: <p>I'm running into an issue with the POST of a pdf file. After recording a HAR file in Gatling 2.1.7, here's what I have:</p>
  
  <pre><code>.exec(http("request_10")
          .post("/api/data/files?revisionId=e9af2c93-d8df-4424-b307-df4c4abbaad1&amp;uploadType=read_only_file&amp;fileType=application%2Fpdf&amp;fileName=testdocument.pdf&amp;fileSize=10080&amp;copyToEditable=true")
          .headers(Map(
              "Accept-Encoding" -&gt; "gzip, deflate",
              "Content-Type" -&gt; "multipart/form-data; boundary=----WebKitFormBoundaryawCJ4mjL1imiO7Ye"
              "Origin" -&gt; url))
          .body(RawFileBody("RecordedSimulation_0010_request.txt")))
  </code></pre>
  
  <p>With the contents of <code>RecordedSimulation_0010_request.txt</code>:</p>
  
  <pre><code>------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableChunkNumber"
  
  1
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableChunkSize"
  
  1048576
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableCurrentChunkSize"
  
  10080
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableTotalSize"
  
  10080
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableType"
  
  application/pdf
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableIdentifier"
  
  66dc65bf-265d-4363-96fd-7fc13f8ceda4
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableFilename"
  
  testdocument.pdf
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableRelativePath"
  
  testdocument.pdf
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="resumableTotalChunks"
  
  1
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye
  Content-Disposition: form-data; name="file"; filename="blob"
  Content-Type: application/octet-stream
  
  
  ------WebKitFormBoundaryawCJ4mjL1imiO7Ye--
  </code></pre>
  
  <p>This doesn't work when I try to play it back (presumably due to the unique IDs), so (after sticking <code>testdocument.pdf</code> in the bodies folder) I've done the following:</p>
  
  <pre><code>val documentFeeder = Iterator.continually(Map(
          "documentBoundary" -&gt; (Random.alphanumeric.take(16).mkString),
          "documentUuid" -&gt; ((Random.alphanumeric.take(8).mkString + "-" +
                             Random.alphanumeric.take(4).mkString + "-" + 
                             Random.alphanumeric.take(4).mkString + "-" +
                             Random.alphanumeric.take(4).mkString + "-" +
                             Random.alphanumeric.take(12).mkString).toLowerCase)))
  
  ...
  
  .feed(documentFeeder)
  // a previous exec POST with a check to grab the documentRevisionId
  
  .exec(http("Post document: upload the file")
              .post("/api/data/files")
              .queryParamMap(Map(
                  "revisionId" -&gt; "${documentRevisionId}",
                  "uploadType" -&gt; "read_only_file",
                  "fileType" -&gt; "application%2Fpdf",
                  "fileName" -&gt; "testdocument.pdf",
                  "fileSize" -&gt; "10080",
                  "copyToEditable" -&gt; "true"))
              .headers(Map(
                  "Accept-Encoding" -&gt; "gzip, deflate",
                  "Content-Type" -&gt; "multipart/form-data; boundary=----WebKitFormBoundary${documentBoundary}"
                  "Origin" -&gt; url))
  
              .body(StringBody("""------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableChunkNumber"
  
                                  1
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableChunkSize"
  
                                  1048576
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableCurrentChunkSize"
  
                                  10080
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableTotalSize"
  
                                  10080
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableType"
  
                                  application/pdf
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableIdentifier"
  
                                  ${documentUuid}
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableFilename"
  
                                  testdocument.pdf
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableRelativePath"
  
                                  testdocument.pdf
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="resumableTotalChunks"
  
                                  1
                                  ------WebKitFormBoundary${documentBoundary}
                                  Content-Disposition: form-data; name="file"; filename="blob"
                                  Content-Type: application/octet-stream
                                  Content-Transfer-Encoding: BINARY
  
  
                                  ------WebKitFormBoundary${documentBoundary}--""")))
  </code></pre>
  
  <p>Lastly, here's the Node.js code to POST dummy data in our app (I'm using this as reference since I know it works):</p>
  
  <pre><code>var resumableData = {
          resumableChunkNumber: 1,
          resumableChunkSize: 1048576,
          resumableCurrentChunkSize: file.size,
          resumableTotalSize: file.size,
          resumableType: guessBestMimeType(file.name, file.type),
          resumableIdentifier: genUuid(),
          resumableFilename: file.name,
          resumableRelativePath: file.name,
          resumableTotalChunks:1
      };
  
      var boundaryKey = Math.random().toString(16); // random string
  
      // the header for the one and only part (need to use CRLF here)
      var resumableBody = '';
  
      for(var resumablePart in resumableData){
          if(resumableData.hasOwnProperty(resumablePart)){
              resumableBody +=
                  '--' + boundaryKey + '\r\n' +
                  'Content-Disposition: form-data; name="' + resumablePart + '"\r\n\r\n' +
                  resumableData[resumablePart] + '\r\n';
          }
      }
      resumableBody +=
          '--' + boundaryKey + '\r\n' +
          'Content-Disposition: form-data; name="file"; filename="blob"\r\n' +
              // use your file's mime type here, if known
          'Content-Type: application/octet-stream\r\n' +
          'Content-Transfer-Encoding: BINARY\r\n\r\n';
  
      var resumableEnd = '\r\n--' + boundaryKey + '--';
  
      var request = https.request({
          method : 'POST',
          host : config.API_HOST + config.BASE_URL,
          port : config.API_PORT,
          path : generateUrl(documentRevision, file, fileType, convertEditable, copyToEditable),
          headers : {
              'Content-Type': 'multipart/form-data; boundary='+boundaryKey,
              'Content-Length' : file.size + Buffer.byteLength(resumableBody + resumableEnd, 'utf-8')
          }
      }, function (response) {
          var data = '';
          response.on('data', function(chunk) {
              data += chunk.toString();
          });
          response.on('end', function() {
              resolve(JSON.parse(data));
          });
          response.on('error', function(err){
              console.error(err);
              reject(err);
          });
      });
  
      request.write(resumableBody);
      fs.createReadStream(file.path, { bufferSize: 4 * 1024})
          .on('end', function() {
              request.end(resumableEnd);
          })
          .pipe(request, { end: false });
  </code></pre>
  
  <p>I've been working on troubleshooting this for a couple days and this is my first foray into Scala and Gatling. What am I missing here to get this POST? </p>
  
  <p>One issue (although it could be a red herring) that stands out is that my app uses <code>Content-Length</code> in the header - is this necessary, given that Gatling has omitted it? If it is necessary, am I able to insert the number in Gatling without hardcoding it?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>After reading this <a href="https://groups.google.com/forum/#!msg/gatling/Arm3gnOqYpI/wLnJgz5CsOwJ" rel="noreferrer">post</a> I tried the following:</p>
  
  <pre><code>.exec(http("test post")
              .post("/api/data/files")
              .headers(Headers.headers_6)
              .formParamMap(Map(
                  "revisionId" -&gt; "${documentRevisionId}",
                  "uploadType" -&gt; "read_only_file",
                  "fileType" -&gt; "application%2Fpdf",
                  "fileName" -&gt; "testdocument.pdf",
                  "fileSize" -&gt; "10080",
                  "copyToEditable" -&gt; "true"))
              .bodyPart(StringBodyPart("""{ "resumableChunkNumber": "1",
                  "resumableChunkSize": "1048576",
                  "resumableCurrentChunkSize": "10080",
                  "resumableTotalSize": "10080",
                  "resumableType": "application/pdf",
                  "resumableIdentifier": "${documentUuid}",
                  "resumableFilename": "testdocument.pdf",
                  "resumableRelativePath": "testdocument.pdf",
                  "resumableTotalChunks": "1" }""")).asJSON
              .bodyPart(RawFileBodyPart("file", "testdocument.pdf")
                  .fileName("testdocument.pdf")
                  .transferEncoding("binary")).asMultipartForm)
  </code></pre>
  
  <p>But I still haven't had success. Any suggestions on moving forward?</p>