From 5ee371d1b3dbd527045644544d8460140e31cf35 Mon Sep 17 00:00:00 2001 From: Harun Kilic Date: Fri, 26 Nov 2021 09:10:02 +0100 Subject: [PATCH] fix(core): Fix stream not being instance of ReadStream (#1238) The stream will not be recognized as ReadStream if used createReadStream from the regular FS package. This will fix it. --- packages/core/src/service/services/asset.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/service/services/asset.service.ts b/packages/core/src/service/services/asset.service.ts index 79775bc247..2bab42e5f1 100644 --- a/packages/core/src/service/services/asset.service.ts +++ b/packages/core/src/service/services/asset.service.ts @@ -16,6 +16,7 @@ import { ID, PaginatedList, Type } from '@vendure/common/lib/shared-types'; import { notNullOrUndefined } from '@vendure/common/lib/shared-utils'; import { unique } from '@vendure/common/lib/unique'; import { ReadStream } from 'fs-extra'; +import { ReadStream as FSReadStream } from 'fs'; import mime from 'mime-types'; import path from 'path'; import { Readable, Stream } from 'stream'; @@ -393,7 +394,7 @@ export class AssetService { stream: ReadStream | Readable, maybeFilePath?: string, ): Promise { - const filePath = stream instanceof ReadStream ? stream.path : maybeFilePath; + const filePath = stream instanceof ReadStream || stream instanceof FSReadStream ? stream.path : maybeFilePath; if (typeof filePath === 'string') { const filename = path.basename(filePath); const mimetype = mime.lookup(filename) || 'application/octet-stream';