How to POST /assets

Hi there,
I'm trying to upload an asset using POST /assets. I can't figure out how to send the file data, however. Currently, my code looks like this:
const upload = (body: {
    file: File;
  }) => {
    const form = new FormData();

    const uuid = crypto.randomUUID();
    const now = new Date().toISOString();

    form.set("assetData", body.file);
    form.set("deviceId", uuid);
    form.set("deviceAssetId", uuid);
    form.set("fileCreatedAt", now);
    form.set("fileModifiedAt", now);

    return request("/assets", {
      body: form,
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type":
          "multipart/form-data; boundary=---WebKitFormBoundary7MA4YWxkTrZu0gW",
      },
    });
  }


If I exclude the Content-Type header, I get a validation error saying the various fields are missing.
If I add Content-Type: multipart/form-data, I get a Multipart: Boundary not found error.
If I add Content-Type: multipart/form-data; boundary=---WebKitFormBoundary7MA4YWxkTrZu0gW, I get a Multipart: Unexpected end of form error.
I found that boundary value in a few places on the web, but it doesn't seem to work.

I'm not sure how to proceed. How do I upload an asset?
Was this page helpful?