Custom Upload provider: can't find module

Required System information

  • Node.js version: 18.x
  • NPM version: 8.5.x
  • Strapi version: 4.10.5
  • Database: sqlite
  • Operating system: MacOs
  • Is your project Javascript or Typescript: js

Describe the Question

I’m trying to create a custom upload provider for Strapi, where I have built a file server and I want to use it with Strapi as the main file server for uploading media files, I have followed the docs about creating a local upload provider.

I have created a directory in the main Strapi folder as Providers/strapi-provider-upload-custom-media and in the provider I have created an index.js file with the following logic:



"use strict";

import { axios } from "axios";
import FormData from "form-data";

export function init(providerOptions) {
  const client = axios.create({
    baseURL: providerOptions.apiUrl,
    headers: {
      "X-API-KEY": providerOptions.apiKey,
    },
  });

  return {
    upload(file) {
      const formData = new FormData();
      formData.append("file", file.buffer, {
        filename: file.name,
      });
      formData.append("folder", "image");

      return client.post("/fs/upload", formData).then((response) => {
        file.hash = response.data.key;
        file.url = response.data.url;

        return file;
      });
    },

    uploadStream(file) {
      return upload(file);
    },

    delete(file) {
      return client.delete("/fs/" + file.hash).then(() => {
        return;
      });
    },
    isPrivate() {
      return false;
    },
  };
}


in the Strapi Config folder I’ve created a file called plugins.js directory, and it is having the follwoing logic:



module.exports = ({ env }) => ({
  upload: {
    config: {
      provider: "custom-media",
      providerOptions: {
        apiUrl: env("MEDIA_API_URL"),
        apiKey: env("MEDIA_API_KEY"),
      },
    },
  },
});


and in the *packages.json i have defined:


 "strapi-provider-upload-custom-media": "file:providers/strapi-provider-upload-custom-media"

Now, if i hit yarn and trying to run it with yarn develop I encountr the following error:

saifj@Saifs-MacBook-Air Q_Prodsucts_Managment % yarn develop       
yarn run v1.22.18
$ strapi develop
Error: Cannot find module 'custom-media'

Try using full name strapi-provider-upload-custom-media in plugins.js