|
|
@@ -8,7 +8,7 @@ import { SysConfigReaderService } from '@box/core/sys-config/sys-config-reader.s
|
|
|
import * as path from 'path';
|
|
|
import { createReadStream, createWriteStream } from 'fs';
|
|
|
import { mkdir, rm } from 'fs/promises';
|
|
|
-import { Transform, pipeline as pipelineCallback } from 'stream';
|
|
|
+import { Readable, Transform, pipeline as pipelineCallback } from 'stream';
|
|
|
import { promisify } from 'util';
|
|
|
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
|
|
|
|
@@ -204,7 +204,22 @@ export class UploaderService {
|
|
|
maxBytes: number,
|
|
|
rootPath: string,
|
|
|
): Promise<string> {
|
|
|
- const source = file.file as NodeJS.ReadableStream;
|
|
|
+ let source = file.file as NodeJS.ReadableStream | undefined;
|
|
|
+ if (!source) {
|
|
|
+ const maybeBuffer =
|
|
|
+ (file as any).buffer ??
|
|
|
+ (file as any).value ??
|
|
|
+ (file as any).data ??
|
|
|
+ undefined;
|
|
|
+ if (Buffer.isBuffer(maybeBuffer)) {
|
|
|
+ source = Readable.from(maybeBuffer);
|
|
|
+ } else if (typeof (file as any).toBuffer === 'function') {
|
|
|
+ const buffer = await (file as any).toBuffer();
|
|
|
+ if (Buffer.isBuffer(buffer)) {
|
|
|
+ source = Readable.from(buffer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!source) {
|
|
|
throw new BadRequestException('Upload stream is missing');
|
|
|
}
|