Image upload plugin in nodebb 2.x

NodeBB Development
  • Hello ,
    I want to use a remote storage (s3 bucket) for storage instead of storing uploaded images locally in uploads dir.
    I have tried nodebb-plugin-s3-uploads and all its forks found on npm but they all have a common error

    TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
        at Object.stat (node:internal/fs/promises:660:10)
        at processDir (/usr/src/app/src/plugins/data.js:110:36)
        at async Promise.all (index 0)
        at async Data.getStaticDirectories (/usr/src/app/src/plugins/data.js:128:2)

    I am using a clean install of nodebb docker v2.3 , all these plugins haven't been update for over a years.
    Can someone link me a working remote storage plugin ?
    Any insights on cause of error ?
    Is there any basic skeleton available to write the plugin myself ?

    Thank you for your time

  • @aditya-appyhigh Hi. Your message got kind of buried in the forum. This is a frustrating bug where you need to make the directory "public" in the module path. NodeBB requires that file paths actually exist for things to compile even if nothing is at the path.

    To fix go to your module directory from the nodebb root.

    Mine is here:

    mkdir /var/www/nodebb/node_modules/nodebb-plugin-s3-uploads-updated/public

    Then retry ./nodebb build

  • @greyhat That sounds like a bug with the plugin, then, no?

    The plugin should provide the empty directory (you can do that and have it source controlled by putting in an empty .gitignore file into it), and then NodeBB won't error out.

    I mean, yes, I could have NodeBB ignore static directories when the directory doesn't exist, but then the plugin might break because it expects said directory to exist 🤔 Sort of a catch-22.

  • More specifically, the issue is that it defines a static directory in plugin.json:

    "staticDirs": {
      "s3": "public"

    But doesn't have it.

    It seems to be an artifact of people forking and updating it without fully understanding what exactly it was doing - looking back at some history at some point someone moved the templates from public/templates to just templates/ and apparently NodeBB wasn't enforcing that directories have to exist at that point, so it wasn't noticed and all future forks inherited this bug.

    NodeBB is IMO doing fine here - a lack of directory a plugin declared to have might suggest some issue with the installation or the plugin itself (for example a typo in a path). A plugin incorrectly declaring something it doesn't use can't really be distinguished from these issues.

    Also, @julian while .gitignore works, I feel like it's a bit of abuse of that feature and the name is misleading (upon seeing a directory with .gitignore my first thought would be that something is supposed to go there but will be ignored. And I feel without knowing much about git I might've assumed it meant the whole directory would be ignored by git - the opposite of what it actually does). I personally prefer the convention of using an empty file named .gitkeep (or just .keep), since it more obviously refers to keeping the directory and wouldn't have any other potential impact on files included by git.

    EDIT: TL;DR of the issue:
    why would nodebb do this

Suggested Topics