imp(middleware-multipart): req.file -> req.files
MODIFY
packages/@integration/src/effects/static.effects.ts
packages/@integration/src/effects/static.effects.ts
@@ -24,7 +24,7 @@ const postFile$ = r.pipe(
})),
map(req => ({
body: {
- file: req.file,
+ file: req.files,
body: req.body,
},
}))

MODIFY
packages/middleware-multipart/README.md
packages/middleware-multipart/README.md
@@ -40,7 +40,7 @@ const effect$ = r.pipe(
r.useEffect(req$ => req$.pipe(
use(multipart$()),
map(req => ({ body: {
- file: req.file['image_1'], // file information
+ files: req.files['image_1'], // file information
body: req.body, // all incoming body fields
}}))
)));
@@ -66,7 +66,7 @@ const effect$ = r.pipe(
files: ['image_1'],
})),
map(req => ({ body: {
- file: req.file['image_1'], // file information
+ files: req.files['image_1'], // file information
body: req.body, // all incoming body fields
}}))
)));

MODIFY
packages/middleware-multipart/src/multipart.interface.ts
packages/middleware-multipart/src/multipart.interface.ts
@@ -19,7 +19,7 @@ export interface FileIncomingData {
};
export interface WithFile<T extends string = string> {
- file: Record<T, File>;
+ files: Record<T, File>;
}
interface StreamHandlerOutput {

MODIFY
packages/middleware-multipart/src/multipart.util.ts
packages/middleware-multipart/src/multipart.util.ts
@@ -23,8 +23,8 @@ export const setRequestData =
(req: HttpRequest) =>
(incomingFile: FileIncomingData) =>
({ buffer, destination, size }: ComputedFileData) => {
- req.file = {
- ...req.file || {},
+ req.files = {
+ ...req.files || {},
[incomingFile.fieldname]: {
size,
buffer,

MODIFY
packages/middleware-multipart/src/specs/multipart.middleware.spec.ts
packages/middleware-multipart/src/specs/multipart.middleware.spec.ts
@@ -14,7 +14,7 @@ const memoryMultipart$ = r.pipe(
r.useEffect(req$ => req$.pipe(
use(multipart$()),
map(req => ({ body: {
- file: req.file,
+ files: req.files,
fields: req.body,
}}))
)));
@@ -29,7 +29,7 @@ const memoryWithOptionsMultipart$ = r.pipe(
maxFileSize: 20,
})),
map(req => ({ body: {
- file: req.file,
+ files: req.files,
fields: req.body,
}}))
)));
@@ -42,7 +42,7 @@ const filesystemMultipart$ = r.pipe(
stream: streamFileTo(TMP_PATH),
})),
map(req => ({ body: {
- file: req.file,
+ files: req.files,
fields: req.body,
}}))
)));
@@ -67,13 +67,13 @@ describe('multipart$', () => {
.expect(200)
.then(({ body }) => {
// data_field
- expect(body.file.data_field.size).toEqual(Buffer.byteLength(data));
- expect(body.file.data_field.destination).toBeUndefined();
- expect(body.file.data_field.filename).toBeUndefined();
- expect(body.file.data_field.encoding).toEqual('7bit');
- expect(body.file.data_field.mimetype).toEqual('application/octet-stream');
- expect(body.file.data_field.fieldname).toEqual('data_field');
- expect(data.equals(Buffer.from(body.file.data_field.buffer))).toBe(true);
+ expect(body.files.data_field.size).toEqual(Buffer.byteLength(data));
+ expect(body.files.data_field.destination).toBeUndefined();
+ expect(body.files.data_field.filename).toBeUndefined();
+ expect(body.files.data_field.encoding).toEqual('7bit');
+ expect(body.files.data_field.mimetype).toEqual('application/octet-stream');
+ expect(body.files.data_field.fieldname).toEqual('data_field');
+ expect(data.equals(Buffer.from(body.files.data_field.buffer))).toBe(true);
// field_1, field_2
expect(body.fields.field_1).toEqual('test_1');
@@ -94,13 +94,13 @@ describe('multipart$', () => {
.expect(200)
.then(({ body }) => {
// data_field
- expect(body.file.data_field.size).toBeUndefined();
- expect(body.file.data_field.destination).toEqual(savedFilePath);
- expect(body.file.data_field.filename).toEqual('README.md');
- expect(body.file.data_field.encoding).toEqual('7bit');
- expect(body.file.data_field.mimetype).toEqual('text/markdown');
- expect(body.file.data_field.fieldname).toEqual('data_field');
- expect(body.file.data_field.buffer).toBeUndefined();
+ expect(body.files.data_field.size).toBeUndefined();
+ expect(body.files.data_field.destination).toEqual(savedFilePath);
+ expect(body.files.data_field.filename).toEqual('README.md');
+ expect(body.files.data_field.encoding).toEqual('7bit');
+ expect(body.files.data_field.mimetype).toEqual('text/markdown');
+ expect(body.files.data_field.fieldname).toEqual('data_field');
+ expect(body.files.data_field.buffer).toBeUndefined();
expect(fs.readFileSync(savedFilePath)).toBeDefined();
// field_1, field_2

MODIFY
packages/middleware-multipart/src/specs/multipart.util.spec.ts
packages/middleware-multipart/src/specs/multipart.util.spec.ts
@@ -57,7 +57,7 @@ test('#setRequestData sets file related request data', () => {
setRequestData(incomingHttpRequest)(incomingFile)(computedFileData);
// then
- expect(incomingHttpRequest.file).toEqual({
+ expect(incomingHttpRequest.files).toEqual({
'image_1': {
size: bufferedDataLength,
buffer: bufferedData,

imp(middleware-multipart): req.file -> req.files