[v4] Uploading file during entry creation

System Information
  • Strapi Version: 4.0.5
  • Database: AWS PostgreSQL

I have the following code to upload an image and create an entry. It used to work just fine in v3:

const formData = new FormData()
const temp = {
  title: this.submitAssignmentFormData.title,
  description: this.submitAssignmentFormData.description,
  assignment: this.$route.params.id,
formData.append('data', JSON.stringify(temp))

this.$axios.post('/assignment-works', formData) // that actually goes to http://localhost:1337/api/assignment-works
  .then(res => {
    // ...do something with res
  .catch(err => {

As I said above, it used to work just fine in v3. Now that I’m rewriting everything to v4 I’m getting the following error 400:

Invalid payload submitted for the creation of an entity of type assignmentWork. Expected an object, but got undefined

Looking at the request I see that I’m sending the following as payload:

Content-Disposition: form-data; name="data"

{"title":"My image","description":"","assignment":"1"}
Content-Disposition: form-data; name="files.file"; filename="IKP_3729 copy.jpg"
Content-Type: image/jpeg

ÿØÿáñExif... rest of the image code

I tried to console log the form data


and I’m getting the object with all the data:

Object { data: "{\"title\":\"My image\",\"description\":\"\",\"assignment\":\"1\"}", "files.file": File }

So why am I getting this error all of a sudden? What am I doing wrong and how to make it work?

any news with the above?