Lifecycle hook and field population

System Information
  • Strapi Version: 4.1.5
  • Operating System: MacOS
  • Database:
  • Node Version: v16.13.2
  • NPM Version: 8.5.1
  • Yarn Version:


I have a small model which expects a link and I want to fetch the favicon for that link and store it in the Media Library. My original intention is to have a button in the Content Manger like Fetch Favicon but I didn’t know how to realize that. I am quite new to Strapi. I did choose now lifecycle hooks but later realized that afterUpdate might help in backfilling my data but afterCreate is what I actually need.

(If somebody can point in to a better concept into realizing that, please let me know.)

Besides that I have the following questions:

  1. I use populate: "*" (because this model stands in relation to another model). Besides the favicon field I have some other Boolean fields in the same model. They all do get fetched/populated correctly but the favicon is not visible. Why could that be?

  2. I do need to reload the Content Manager in order to see the uploaded favicon in the Content Manager view where I enter also the link - in order to see the uploaded favicon being displayed in the model component. Is there some way to automatically update that view without a reload?

  3. What better approach could I have taken to realize the below functionality in the Strapi system? I saw services but am not sure.

    "favicon": {
      "type": "media",
      "multiple": false,
      "required": false,
      "allowedTypes": [
    "link": {
      "type": "string",
      "unique": true,
      "required": true
const axios = require("axios");
const mime = require("mime-types");
const fs = require("fs");
const tmp = require("tmp");

module.exports = {
  // Needs to be afterCreate() otherwise new entries won't get icons.
  async afterUpdate(event) {
    const { params, result } = event;

    // How to overwrite a file when uploading insteading creating duplicates?
    if ( {
      console.log("Icon already exists.");
    console.log(`Icon: ${}`);

    let link =;
    if (!link) {
    const faviconLink = `${link}`;

    const response = await axios(faviconLink, { responseType: "arraybuffer" });
    if (!response) {
      console.log(`fetch(): ${response.status}`);
    const mimeType = response.headers["content-type"];
    const fileName = new URL(link).hostname;

    const tempFileName = tmp.fileSync();

    const stats = fs.statSync(;
    try {
        data: {
          ref: "",
          field: "favicon",
        files: {
          name: fileName,
          type: mimeType,
          size: stats.size,
    } catch (error) {
      console.error(`Error: ${error}`);