System Information
- Strapi Version: v5.5.1
- Operating System: node:22-alpine (Docker)
- Database: PostgreSQL 16
- Node Version: v22.7.0
- NPM Version: whatever is shipped with the docker image
- Yarn Version:
Hello together,
im running severla times in this issue and not sure how to finally solve that.
Every then and now while updating documents (via graphql and rest api) i receive the following error (or something alike):
insert into "home_contents" ("created_at", "created_by_id", "document_id", "explore", "intro", "locale", "published_at", "updated_at", "updated_by_id", "welcome") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) returning "id" - invalid byte sequence for encoding "UTF8": 0xe4 0x6c 0x74
I already tried to solve that by adding a middleware to ensure UTF encoding on every request:
// src/middlewares/enforceencoding.ts
/**
* `enforceencoding` middleware
*/
import type { Core } from '@strapi/strapi';
function encodeStrings(obj: Record<string, unknown>) {
for (const key in obj) {
if (typeof obj[key] === 'string') {
obj[key] = Buffer.from(obj[key] as string, 'utf-8').toString();
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
encodeStrings(obj[key] as Record<string, unknown>);
}
}
}
export default (config, { strapi }: { strapi: Core.Strapi }) => {
return async (ctx, next) => {
if (ctx.request.body) {
encodeStrings(ctx.request.body);
}
await next();
};
};
This first occurred when storing some special character (like “ä”, “ö”, “ü”, “ß”, etc) and after adding the middleware it seemed to work since i could successfully send the same request with the same content. So i went ahead and several requests later the issue came back.
So im not really sure if the middleware is properly integrated, since it should ensure UTF8 for every request, or if i overlooked something more basic.
Im grateful for every hint from the strapi pros
Thanks in advance