typescriptpostmanplaywrightmultipartform-data

How to mimic form-data list with nested type that contains file in typescript?


I got following form - I can easily "attach" the file for the root fruit_image property in typescript but not when it's a part of list fruits[0] of given type where the file is. How to accomplish that? enter image description here

import fs from 'fs';
import path from 'path';
const fruitImage = fs.readFileSync(path.resolve(__dirname, './fruit-image.png'));

export const form = () => {
    return {
        id: 'some id',
        //below ok - got byte array
        fruit_image: {
            name: 'fruit-image.png',
            mimeType: 'png',
            buffer: fruitImage,
        },
        //below is not ok - posting this to endpoint results in null list
        fruits: [
            {
                id: 'banana',
                fruit_image: { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }
            }
        ]
    };
};


Solution

  • Instead of this:

            //below is not ok - posting this to endpoint results in null list
            fruits: [
                {
                    id: 'banana',
                    fruit_image: { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }
                }
            ]
    

    This:

      'fruits[0].id': 'banana',
      'fruits[0].fruit_image': { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }