Search code examples
binaryloadload-testingbinary-dataartillery

Artillery.io - POST binary data


How would you send a POST request via artillery with binary data? More specifically I'm trying to do a batch request and have artillery read from the file for the body

I did see in the docs I need to use a custom JS function, but can't seem to get it to correctly pass back the values to artillery:

https://artillery.io/docs/http-reference/#advanced-writing-custom-logic-in-javascript


Solution

  • i read the post that custom js can be written as followed:

    'use strict';
     module.exports = {
      generateRandomPayload
    };
    var contents = require('fs').readFileSync("/home/ec2-user/image_data/data6.json");
    
    function generateRandomPayload(userContext, events, done) {
      var payload = {
        "data":"data"
      };
    payload = JSON.parse(contents);
    userContext.vars.payload = payload;
    return done();
    }
    

    the artillery yaml file can be like so:

    config:
    target: "https://0giahrna63.execute-api.us-east-1.amazonaws.com/Prod/"
    processor: "./image-payload.js"
    phases:
       - duration: 120
       - arrivalRate: 1
    scenarios:
       - flow:
       - function: "generateRandomPayload"
       - post:
          url: "/resource"
          json: "{{payload}}"