Skip to content

Commit

Permalink
changelog indent
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Dec 4, 2024
1 parent 3d0b316 commit 3e28430
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,56 @@ Thanks for the new solution, the multipart fields and request parameters are sen

```js
module.exports = {
name: "file",
actions: {
save: {
handler(ctx) {
return new this.Promise((resolve, reject) => {
const filePath = path.join(uploadDir, ctx.params.$filename);
const f = fs.createWriteStream(filePath);
f.on("close", () => {
// File written successfully
this.logger.info(`Uploaded file stored in '${filePath}'`);
resolve({ filePath });
});

ctx.stream.on("error", err => {
this.logger.info("File error received", err.message);
reject(err);

// Destroy the local file
f.destroy(err);
});

f.on("error", () => {
// Remove the errored file.
fs.unlinkSync(filePath);
});

ctx.stream.pipe(f);
});
}
}
}
name: "file",
actions: {
save: {
handler(ctx) {
return new this.Promise((resolve, reject) => {
const filePath = path.join(uploadDir, ctx.params.$filename);
const f = fs.createWriteStream(filePath);
f.on("close", () => {
// File written successfully
this.logger.info(`Uploaded file stored in '${filePath}'`);
resolve({ filePath });
});

ctx.stream.on("error", err => {
this.logger.info("File error received", err.message);
reject(err);

// Destroy the local file
f.destroy(err);
});

f.on("error", () => {
// Remove the errored file.
fs.unlinkSync(filePath);
});

ctx.stream.pipe(f);
});
}
}
}
};
```

Example content of `ctx.params`:

```json
{
// Multipart file properties
$fieldname: "myfile",
$filename: "avatar.png",
$encoding: "7bit",
$mimetype: "image/png",
// Other multipart fields
// e.g.: `<input type="text" name="name" id="name" value="Test User">`
name: "Test User",

// Request path parameter, e.g.: `/upload/single/1234`
id: "1234"
// Multipart file properties
$fieldname: "myfile",
$filename: "avatar.png",
$encoding: "7bit",
$mimetype: "image/png",
// Other multipart fields
// e.g.: `<input type="text" name="name" id="name" value="Test User">`
name: "Test User",

// Request path parameter, e.g.: `/upload/single/1234`
id: "1234"
}
```

Expand Down

0 comments on commit 3e28430

Please sign in to comment.