From ee8b26f3833d269acaba690441561ba5717d0a20 Mon Sep 17 00:00:00 2001 From: Emi Rexhepi Date: Fri, 6 Feb 2026 15:30:02 +0100 Subject: [PATCH] fix(api): preserve file extension in upload-from-url endpoint The upload-from-url endpoint passed an empty originalname to uploadFile(), causing extname('') to return '' and files to be saved without an extension. Derive the extension from the response Content-Type header (or URL fallback) so files are stored with the correct extension on disk. Fixes gitroomhq/postiz-app#1147 Co-Authored-By: Claude Opus 4.6 --- .../routes/v1/public.integrations.controller.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts index 2655f699..eb71201c 100644 --- a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts +++ b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts @@ -29,7 +29,7 @@ import { VideoFunctionDto } from '@gitroom/nestjs-libraries/dtos/videos/video.fu import { UploadDto } from '@gitroom/nestjs-libraries/dtos/media/upload.dto'; import axios from 'axios'; import { Readable } from 'stream'; -import { lookup } from 'mime-types'; +import { lookup, extension } from 'mime-types'; import * as Sentry from '@sentry/nestjs'; @ApiTags('Public API') @@ -73,17 +73,21 @@ export class PublicIntegrationsController { }); const buffer = Buffer.from(response.data); + const responseMime = response.headers?.['content-type']?.split(';')[0]?.trim(); + const urlMime = lookup(body?.url?.split?.('?')?.[0]); + const mimetype = (urlMime || responseMime || 'image/jpeg') as string; + const ext = extension(mimetype) || 'jpg'; const getFile = await this.storage.uploadFile({ buffer, - mimetype: lookup(body?.url?.split?.('?')?.[0]) || 'image/jpeg', + mimetype, size: buffer.length, path: '', fieldname: '', destination: '', stream: new Readable(), filename: '', - originalname: '', + originalname: `upload.${ext}`, encoding: '', });