|
|
@@ -204,19 +204,36 @@ export class UploaderService {
|
|
|
maxBytes: number,
|
|
|
rootPath: string,
|
|
|
): Promise<string> {
|
|
|
+ const toBuffer = (value: unknown): Buffer | undefined => {
|
|
|
+ if (!value) return undefined;
|
|
|
+ if (Buffer.isBuffer(value)) return value;
|
|
|
+ if (value instanceof Uint8Array) return Buffer.from(value);
|
|
|
+ if (Array.isArray(value)) return Buffer.from(value);
|
|
|
+ if (typeof value === 'object') {
|
|
|
+ try {
|
|
|
+ return Buffer.from(value as ArrayLike<number>);
|
|
|
+ } catch {
|
|
|
+ return undefined;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return undefined;
|
|
|
+ };
|
|
|
+
|
|
|
let source = (file as any)?.file as NodeJS.ReadableStream | undefined;
|
|
|
if (!source) {
|
|
|
- if (Buffer.isBuffer(file) || file instanceof Uint8Array) {
|
|
|
- source = Readable.from(file);
|
|
|
+ const buffer = toBuffer(file);
|
|
|
+ if (buffer) {
|
|
|
+ source = Readable.from(buffer);
|
|
|
}
|
|
|
}
|
|
|
if (!source) {
|
|
|
- const maybeBuffer =
|
|
|
+ const maybeBuffer = toBuffer(
|
|
|
(file as any).buffer ??
|
|
|
(file as any).value ??
|
|
|
(file as any).data ??
|
|
|
- undefined;
|
|
|
- if (Buffer.isBuffer(maybeBuffer)) {
|
|
|
+ undefined,
|
|
|
+ );
|
|
|
+ if (maybeBuffer) {
|
|
|
source = Readable.from(maybeBuffer);
|
|
|
} else if (typeof (file as any).toBuffer === 'function') {
|
|
|
const buffer = await (file as any).toBuffer();
|