-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
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:
Code snippets
At this point I implemented this code inside the file located in this path ./src/index.js:
- 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));
});
}
- 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! 😎
