fix: s3 upload compatibility (#14445)
fix #14432 #### PR Dependency Tree * **PR #14445** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved file upload handling to ensure consistent support for different data formats during object and multipart uploads. * Enhanced type safety throughout storage and workflow components by removing unnecessary type assertions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -175,7 +175,7 @@ export class R2StorageProvider extends S3StorageProvider {
|
|||||||
body: Readable | Buffer | Uint8Array | string,
|
body: Readable | Buffer | Uint8Array | string,
|
||||||
options: { contentType?: string; contentLength?: number } = {}
|
options: { contentType?: string; contentLength?: number } = {}
|
||||||
) {
|
) {
|
||||||
return this.client.putObject(key, body as any, {
|
return this.client.putObject(key, this.normalizeBody(body), {
|
||||||
contentType: options.contentType,
|
contentType: options.contentType,
|
||||||
contentLength: options.contentLength,
|
contentLength: options.contentLength,
|
||||||
});
|
});
|
||||||
@@ -192,13 +192,24 @@ export class R2StorageProvider extends S3StorageProvider {
|
|||||||
key,
|
key,
|
||||||
uploadId,
|
uploadId,
|
||||||
partNumber,
|
partNumber,
|
||||||
body as any,
|
this.normalizeBody(body),
|
||||||
{ contentLength: options.contentLength }
|
{ contentLength: options.contentLength }
|
||||||
);
|
);
|
||||||
|
|
||||||
return result.etag;
|
return result.etag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeBody(body: Readable | Buffer | Uint8Array | string) {
|
||||||
|
// s3mini does not accept Node.js Readable directly.
|
||||||
|
// Convert it to Web ReadableStream for compatibility.
|
||||||
|
if (body instanceof Readable) {
|
||||||
|
return Readable.toWeb(body);
|
||||||
|
} else if (typeof body === 'string') {
|
||||||
|
return this.encoder.encode(body);
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
override async get(
|
override async get(
|
||||||
key: string,
|
key: string,
|
||||||
signedUrl?: boolean
|
signedUrl?: boolean
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ export class S3StorageProvider implements StorageProvider {
|
|||||||
|
|
||||||
this.logger.verbose(`Read object \`${key}\``);
|
this.logger.verbose(`Read object \`${key}\``);
|
||||||
return {
|
return {
|
||||||
body: Readable.fromWeb(obj.body as any),
|
body: Readable.fromWeb(obj.body),
|
||||||
metadata: {
|
metadata: {
|
||||||
contentType: contentType ?? 'application/octet-stream',
|
contentType: contentType ?? 'application/octet-stream',
|
||||||
contentLength: contentLength ?? 0,
|
contentLength: contentLength ?? 0,
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ export class CopilotController implements BeforeApplicationShutdown {
|
|||||||
status: data.status,
|
status: data.status,
|
||||||
id: data.node.id,
|
id: data.node.id,
|
||||||
type: data.node.config.nodeType,
|
type: data.node.config.nodeType,
|
||||||
} as any,
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user