Skip to content

Commit

Permalink
feat(core): AssetService can create assets from Readable streams
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Mar 29, 2021
1 parent 92952fb commit 9d80145
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/service/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { unique } from '@vendure/common/lib/unique';
import { ReadStream } from 'fs-extra';
import mime from 'mime-types';
import path from 'path';
import { Stream } from 'stream';
import { Readable, Stream } from 'stream';

import { RequestContext } from '../../api/common/request-context';
import { isGraphQlErrorResult } from '../../common/error/error-result';
Expand Down Expand Up @@ -363,8 +363,13 @@ export class AssetService {
/**
* Create an Asset from a file stream created during data import.
*/
async createFromFileStream(stream: ReadStream): Promise<CreateAssetResult> {
const filePath = stream.path;
async createFromFileStream(stream: ReadStream): Promise<CreateAssetResult>;
async createFromFileStream(stream: Readable, filePath: string): Promise<CreateAssetResult>;
async createFromFileStream(
stream: ReadStream | Readable,
maybeFilePath?: string,
): Promise<CreateAssetResult> {
const filePath = stream instanceof ReadStream ? stream.path : maybeFilePath;
if (typeof filePath === 'string') {
const filename = path.basename(filePath);
const mimetype = mime.lookup(filename) || 'application/octet-stream';
Expand Down

0 comments on commit 9d80145

Please sign in to comment.