Skip to content

Commit 3d0b316

Browse files
committed
changelog
1 parent 7328ad7 commit 3d0b316

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

CHANGELOG.md

+70
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
<a name="0.11.0-beta1"></a>
2+
# 0.11.0-beta1 (2024-12-04)
3+
4+
## Changes
5+
6+
### Using 0.15 new streaming solution
7+
8+
The [email protected] supports Moleculer v0.15.x including the new streaming solution. It means, it doesn't support 0.13 and 0.14 moleculer versions.
9+
10+
Thanks for the new solution, the multipart fields and request parameters are sent via `ctx.params` instead of meta and the file stream is available in `ctx.stream` in action handlers.
11+
12+
**Example**
13+
14+
```js
15+
module.exports = {
16+
name: "file",
17+
actions: {
18+
save: {
19+
handler(ctx) {
20+
return new this.Promise((resolve, reject) => {
21+
const filePath = path.join(uploadDir, ctx.params.$filename);
22+
const f = fs.createWriteStream(filePath);
23+
f.on("close", () => {
24+
// File written successfully
25+
this.logger.info(`Uploaded file stored in '${filePath}'`);
26+
resolve({ filePath });
27+
});
28+
29+
ctx.stream.on("error", err => {
30+
this.logger.info("File error received", err.message);
31+
reject(err);
32+
33+
// Destroy the local file
34+
f.destroy(err);
35+
});
36+
37+
f.on("error", () => {
38+
// Remove the errored file.
39+
fs.unlinkSync(filePath);
40+
});
41+
42+
ctx.stream.pipe(f);
43+
});
44+
}
45+
}
46+
}
47+
};
48+
```
49+
50+
Example content of `ctx.params`:
51+
52+
```json
53+
{
54+
// Multipart file properties
55+
$fieldname: "myfile",
56+
$filename: "avatar.png",
57+
$encoding: "7bit",
58+
$mimetype: "image/png",
59+
60+
// Other multipart fields
61+
// e.g.: `<input type="text" name="name" id="name" value="Test User">`
62+
name: "Test User",
63+
64+
// Request path parameter, e.g.: `/upload/single/1234`
65+
id: "1234"
66+
}
67+
```
68+
69+
70+
-----------------------------
171
<a name="0.10.7"></a>
272
# 0.10.7 (2023-11-12)
373

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"webpack-dev-middleware": "^5.2.1"
6161
},
6262
"peerDependencies": {
63-
"moleculer": "^0.13.0 || ^0.14.0 || ^0.15.0"
63+
"moleculer": "^0.15.0"
6464
},
6565
"dependencies": {
6666
"@fastify/busboy": "^1.0.0",

0 commit comments

Comments
 (0)