holo, how to add a png image or file to formdata in Obsidian, like below this. help !!

holo, how to add a png image or file to formdata in Obsidian, like below this.
help !!

import FormData from 'form-data';

const media = new FormData();
const req: RequestUrlParam = {
    url: url,
    method: 'POST',
    headers: this.getHeaders(),
    body: media.getBuffer(),
};
const resp = await requestUrl(req);

and replace using axios, return this error: has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

 const media = new FormData();
 media.append('media', fs.createReadStream(path));
let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: url,
    headers: { 
    ...this.getHeaders()
    },
    data : media
};
              
const res = await axios.request(config)
console.log(res);

Halo, I use the fetch in nodejs, upload a image to server is ok, but I don’t know how to put the Formdata to body of requestUrl of obsidian, HELP !!!

const req: RequestUrlParam = {
  url: url,
  method: 'POST',
  headers: header,
  body: formDataArrayBuffer, // ??? how to put formdata to there
};
const resp = await requestUrl(req);

fetch support Formdata, whether can also support Formdata in obsidian’ requestUrl

this is requests.request python package encode multipart_formdata func

def encode_multipart_formdata(fields, boundary=None):
    """
    Encode a dictionary of ``fields`` using the multipart/form-data MIME format.

    :param fields:
        Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`).

    :param boundary:
        If not specified, then a random boundary will be generated using
        :func:`urllib3.filepost.choose_boundary`.
    """
    body = BytesIO()
    if boundary is None:
        boundary = choose_boundary()

    for field in iter_field_objects(fields):
        body.write(b("--%s\r\n" % (boundary)))

        writer(body).write(field.render_headers())
        data = field.data

        if isinstance(data, int):
            data = str(data)  # Backwards compatibility

        if isinstance(data, six.text_type):
            writer(body).write(data)
        else:
            body.write(data)

        body.write(b"\r\n")

    body.write(b("--%s--\r\n" % (boundary)))

    content_type = str("multipart/form-data; boundary=%s" % boundary)

    return body.getvalue(), content_type

this very fussy, I support obsidian requestUrl body and also support Formdata type

use the arrayBuffer, I handle this problem. reference here.