Use multipart in lifecycle strapi v4?

I am trying to make a request with some data and on top of that, so I decided to make my request multipart and want to send a file along that I will be uploading and then connecting to the images field I guess, how can I do that?

This topic has been created from a Discord post (1238248201275052063) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

I am using the lifecycle to do some validating

And to create something after clicking a button

If you are making request, with file upload lifecycle is not going to help you much

lifecycle is a database event fired on entity creation

Ok, lifecycle doesn’t count here

I am having another issue

it won’t have the file in there

When I try to use multipart for something that has relations

Like an id, it should probably have connect in it, not sure how to structure the code that way

I am required to install some sort of puglin or configure something to have the files uploaded?

const formData = new FormData();

const data = {
    relation: { id: relationId}

formData.append('body', JSON.stringify({ data })

body? Isn’t it data?

I think body should have attribute data with all the stuff inside

const data = {};
const formData = new FormData();

  .forEach(({ name, type, value, files, ...element }) => {
    if (!['submit', 'file'].includes(type)) {
      data[name] = value;
    } else if (type === 'file') {
      files.forEach((file) => {
        formData.append(`files.${name}`, file,;

formData.append('data', JSON.stringify(data));

I am confused


Why do this?