In the process of migrating to strapi v4 we try to get our various media upload controllers to work.
We send formData via POST to our controller that should create a collectionType page with a dynamicZone content with multiple components.
In the v4 documentation there’s a green hint:
If you want to upload files for a component, you will have to specify the index of the item you want to add the file to: files.my_component_name[the_index].attribute_name
However this is not working for us.
The media is uploaded to the media gallery but not linked to the component inside of the dynamic-zone.
(a media outside of the dynamic-zone gets linked correctly)
So my questions…
Is this even working in v4 or just some “promise for the future”?
In v3 it was files.my_name_of_the_dynamic_zone[the_index].attribute_name - so we also assumed a typo here, but that is also not working.
Can anyone confirm or explain how we can upload images via REST in one request to components inside a dynamic-zone, like we did in v3?
Cheers,
Olaf - lost in v4 migration since 4 days -
In my collection type the non nested media attributes are getting correctly assigned.
Example: files.avatar does work in my formData on save the attribute avatar is filled with the new uploaded file/image.
files.todolist[0].img does not work. The file is uploaded to the media library but is not assigned to my nested field todolist[0].img while todolist is a dynamic zone and at position 0 there is a component with an attribute called img
In strapi v3 I did the exact same thing and it was working fine.
EDIT: I am using a custom controller and no create/update core controller from my entity. I am trying to get this working with my own controller logic
The problem with uploading images to component is also described here:
So it seems to be a bug in v4 and I consider delaying the migration to v4 until basic functionalities work like they did in v3. (though for you this might be not an option)
Hi, I’m also facing the same problem. In my case, I can upload image file to my ‘music’ field when creating entries via strapi.entityService like this:
However, I don’t know how to upload image file to component’s field, what if, my ‘music’ field is within a ‘content’ component, then how can I upload using the method I provided ?