I want to give default image to my content type collection. The image is uploading to media library but is not showing on the collection

System Information
  • Strapi Version: 4
  • Operating System: Mac
  • Database: Postgres
  • Node Version:
  • NPM Version:
  • Yarn Version:

I am facing this issue that my image is uploaded to media library but not showing inside strapi collection (if I am including field value inside data it is showing me this error: error: delete from “files_related_morphs” where (((“related_type” = $1 and “field” = $2 and “related_id” in ($3)))) - value “1684930024903” is out of range for type integer"

My code looks like this now

import { statSync } from "fs";
import { join } from "path";

export default {
  register(/*{ strapi }*/) {},

  async bootstrap({ strapi }) {
    const uploadFile = async (strapi, { data, file }) => {
      const { refId, ref, field } = data;
      const { name, path, type } = file;

      const fileStat = statSync(path);

      console.log(
        "strapi.plugins.upload",
        strapi.plugins.upload.services.upload.upload
      );

      const [uploadedFile] = await strapi.plugins.upload.services.upload.upload(
        {
          data,
          files: {
            path,
            name,
            type,
            size: fileStat.size,
          },
        }
      );

      return uploadedFile;
    };

    const uploadedTodoMedia = await uploadFile(strapi, {
      data: {
        refId: Date.now().toString(),
        ref: "api::setting.setting",
        // field: "logoPng", //if I am using this field it gives me this error 'error: delete from "files_related_morphs" where ((("related_type" = $1 and "field" = $2 and "related_id" in ($3)))) - value "1684930024903" is out of range for type integer
      },
      file: {
        path: join(
          __dirname,
          "../../public/uploads/chassis_only_included_bf30508712.png"
        ),
        name: "genericLogoPng.png",
        type: "image/png",
      },
    });

    console.log(uploadedTodoMedia, "uploadedTodoMedia");

    strapi.entityService.create("api::setting.setting", {
      data: {
        name: "GenericOEM",
        primaryColor: "#000000",
        secondaryColor: "#ffffff",
        logoPng: uploadedTodoMedia.id, // I want to show image here
      },
    });
  },
};

Can someone please tell me what to write inside data object to have image inside my collection.


Here in logoPng?

On discord: Discord

Fixed the issue by truncating my schema of setting.
Putting the code here for others:

import { statSync } from "fs";
import { join } from "path";

const imageFiles = [
  {
    path: join(__dirname, "../../public/uploads/logoPng.png"),
    name: "logoPng.png",
    type: "image/png",
  },
  {
    path: join(__dirname, "../../public/uploads/logoSvg.svg"),
    name: "logoSvg.svg",
    type: "image/svg+xml",
  },
  {
    path: join(__dirname, "../../public/uploads/bannerLogo.png"),
    name: "bannerLogo.png",
    type: "image/png",
  },
  {
    path: join(__dirname, "../../public/uploads/bannerImg.png"),
    name: "bannerImg.png",
    type: "image/png",
  },
];

const uploadFile = async (strapi, { data, file }) => {
  const { name, path, type } = file;

  const fileStat = statSync(path);

  const [uploadedFile] = await strapi.plugins.upload.services.upload.upload({
    data,
    files: {
      path,
      name,
      type,
      size: fileStat.size,
    },
  });

  return uploadedFile;
};

export default {
  /**
   * An asynchronous register function that runs before
   * your application is initialized.
   *
   * This gives you an opportunity to extend code.
   */
  register(/*{ strapi }*/) {},

  /**
   * An asynchronous bootstrap function that runs before
   * your application gets started.
   *
   * This gives you an opportunity to set up your data model,
   * run jobs, or perform some special logic.
   */

  async bootstrap({ strapi }) {
    const uploadedImages = await Promise.all(
      imageFiles.map(async (imageData) => {
        return uploadFile(strapi, {
          data: {},
          file: imageData,
        });
      })
    );


    await strapi.entityService.create("api::setting.setting", {
      data: {
        publishedAt: new Date(),
        name: "GenericABCDOEM",
        primaryColor: "#000000",
        secondaryColor: "#ffffff",
        logoPng: uploadedImages.find((img) => img.name === "logoPng.png").id,
        logoSvg: uploadedImages.find((img) => img.name === "logoSvg.svg").id,
        bannerLogo: uploadedImages.find((img) => img.name === "bannerLogo.png")
          .id,
        bannerImg: uploadedImages.find((img) => img.name === "bannerImg.png"),
      },
    });
  },
};