Hot To Send JSON As File Multipart/form-data

I want test JSON Send as multipart/form-data. So, I change JSON String into File With Blob.
But the k6 is not include Blob library.

my k6 code is below

export default function () {
    let url = "http://localhost:8080/products/1/reviews";

    const fd = new FormData();
    const reviewJSON = JSON.stringify({
        userId : 1,
        score : Math.random() * 5 + 1,
        content : '리뷰 내용',
    })

    const blob = new Blob([reviewJSON], {
        type: "application/json",
    });
    
    fd.append('review', blob);

    http.post(url, fd.body(), {
        headers: { 'Content-Type': 'multipart/form-data; boundary=' + fd.boundary },
    });


    sleep(1);
}

my Test Spring API is below

@PostMapping
    public ResponseEntity<?> createProductReview(
            @PathVariable("productId") Long productId,
            @RequestPart(required = false) MultipartFile file,
            @RequestPart("review") @Valid CreateProductReviewRequest request
    ) {   ...    }

Hi @yuseogi0218,

Welcome to our community forums! :tada:

But the k6 is not include Blob library.

Since one of the recent releases (v0.53 to be more accurate), k6 has indeed support for Blob.

What’s true is that it’s not available by default (globally), as in it is in other JavaScript runtimes, so you need to import it with:
import { Blob } from 'k6/experimental/websockets';

However, I must admit I’m not quite sure you really need to use Blob to send a JSON as multipart/form-data. Can you try by following one of these examples, please?

Of course, you can stay with Blob if you prefer it, you just need to add the import.
Please, let me know if it doesn’t work as expected. Thanks! :pray: