Hi guys,
i have the following code trying to upload images to the Post collection and attach to the repeatable component called “images” with structure [‘image’,‘caption’].
Post collection has fields: long_text (text), profile (ID ref), images (component repeatable)
The images I upload are uploaded correctly but they are not attached to the newly created Post. Can you advise?
Here is the code (I attach image to let you visualise part of the collection fields):
let formdata = new FormData();
//formdata.append(“long_text”, largeTxt)
formdata.append(‘data’, JSON.stringify({“long_text”: largeTxt,‘profile’:userData.user.profiles[0].id}));
postImage.map((item,index) =>(
formdata.append(files.images[${index}].image
, {
uri: item.path,
type: item.mime,
name: ${Date.now()}${item.path.substr(item.path.lastIndexOf('.'))}
,
})
))
//formdata.append(‘profile’,userData.user.profiles[0].id)
console.log(‘formdata’,formdata)
const res = await apiCall(
“POST”,
ApiEndPoints.CreatePost,
formdata,
{
‘Content-Type’: ‘multipart/form-data’,
‘Authorization’:‘bearer’+’ '+userData.jwt
}
);