Skip to content

Add Image into nested components #10478

@nisharg007

Description

@nisharg007

Bug report

Hello, I am very new in strapi and I don't know, how strapi works internally in backend but I have one hosted strapi given by the client and I am working on it.

I have problem to upload image into components component

like

I have one collection called order, on that I have one component called opc and on that I have one component called director and on that I have one field called 'image', I want to upload my image on that and also want to link that.

order > opc > director ( want to upload here in image field )

image

Code

const fileData = new FormData();
fileData.append(
  `files`,
  value,
  `${new Date().getTime()}_${key}_${type[1]}`
);
// fileData.append("ref", "order");
fileData.append("ref", "order.opc.director");
// fileData.append(`refId`, order);
fileData.append(`refId`, order.opc.director.id);
fileData.append(`field`, 'image');
fileData.append(
  "fileInfo",
  JSON.stringify({ alternativeText: value.name })
);
const res = await axios({
  method: "POST",
  url: "https://api.example.com/upload",
  headers: {
    Authorization: `Bearer ${token}`,
    "Content-type": "multipart/form-data",
  },
  data: fileData,
});

is it right code? or I am doing something wrong here?

System

  • Node.js version: 14.17.0
  • NPM version: 7.11.2
  • Operating system: Ubuntu 20.04

can someone please help me to add image on that component?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions