Skip to content

Azure Cloud - strapi-provider-upload-azure-storage - error: strapi.plugin(...).provider.uploadStream is not a function - SOLUTIONS #13613

@Francescoliverio

Description

@Francescoliverio

Bug report

Required System information

  • Node.js version: v16.15.0
  • NPM version: 8.11.0
  • Strapi version: v4.2.0
  • Database: PostgreSQL
  • Operating system: Ubuntu

Describe the bug

I'm using strapi-provider-upload-azure-storage plugin with the new version of Strapi v4.2.0 that allows you to update a custom logo in the Strapi Dashboard and I was struggling with a response error 500 from Strapi in the Dashboard.

Please take a look inside the Chagelog ( https://strapi.io/blog/announcing-strapi-v4.2 )

I found a Workaround to fix this issue! 🚀

This is the Strapi Console error:

strapi_error_uploadStream_function

Code snippets

At this point I implemented this code inside the file located in this path ./src/index.js:

  1. I created a function for converting a Stream to a Buffer with this code:
function stream2buffer(stream) {
  return new Promise((resolve, reject) => {
    const _buf = [];

    stream.on('data', (chunk) => _buf.push(chunk));
    stream.on('end', () => resolve(Buffer.concat(_buf)));
    stream.on('error', (err) => reject(err));
  });
}
  1. I implemented this code before runs the application inside the bootstrap:
bootstrap({ strapi }) {
    /**
     * Temporary workaround for strapi-provider-upload-azure-storage
     */
    strapi.plugins.upload.provider.uploadStream = async (file) => {
      file.buffer = await stream2buffer(file.stream);

      return strapi.plugins.upload.provider.upload(file);
    };
  },

This is the all code in the context:

'use strict';

function stream2buffer(stream) {
  return new Promise((resolve, reject) => {
    const _buf = [];

    stream.on('data', (chunk) => _buf.push(chunk));
    stream.on('end', () => resolve(Buffer.concat(_buf)));
    stream.on('error', (err) => reject(err));
  });
}

module.exports = {
  /**
   * 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.
   *
   */
  bootstrap({ strapi }) {
    /**
     * Temporary workaround for strapi-provider-upload-azure-storage
     */
    strapi.plugins.upload.provider.uploadStream = async (file) => {
      file.buffer = await stream2buffer(file.stream);

      return strapi.plugins.upload.provider.upload(file);
    };
  },
};

Of course this is a workaround but still I fixed my problem with the new version of Strapi v4.2.0
Now I finally allow to Update my custom logo in the Strapi Dashboard.

I hope to help someone that has the same issue

Regards
Francesco 🇮🇹

Ps. I already report the issue to the owner of the library here I sincerely hope that this problem will be resolved! 😎

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