Skip to content

Commit 1c8ab0b

Browse files
Aschenscottinet
authored andcommitted
Add PDF sending example for Request.setResult (#311)
## What does this PR do? Adds an example of sending a PDF using `Request.setResult` ### How should this be manually tested? <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> - Step 1 : - Step 2 : - Step 3 : ... ### Other changes <!-- Please describe here all changes not directly linked to the main issue, but made because of it. For instance: issues spotted during this PR and fixed on-the-fly, dependencies update, and so on --> ### Boyscout <!-- Describe here minor improvements in the code base and not directly linked to the main changes: typos fixes, better/new comments, small code simplification, new debug messages, and so on. -->
1 parent 9041bb3 commit 1c8ab0b

File tree

1 file changed

+21
-0
lines changed
  • src/core/1/plugins/plugin-context/constructors/request

1 file changed

+21
-0
lines changed

src/core/1/plugins/plugin-context/constructors/request/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,24 @@ The `options` argument accepts the following parameters:
164164
| `headers` | <pre>object (null)</pre> | Network specific headers. Shortcut to the [response](https://github.com/kuzzleio/kuzzle-common-objects#requestresponse) header functions |
165165
| `raw` | <pre>boolean (false)</pre> | If `true`, instead of a standard [kuzzle response](/core/1/api/essentials/kuzzle-response), the result is sent as is to the client, without being interpreted |
166166
| `status` | <pre>integer (200)</pre> | Request status |
167+
### Example
168+
169+
Send a PDF
170+
171+
```js
172+
async sendPdf (request) {
173+
const file = fs.readFileSync('./file.pdf');
174+
175+
request.setResult(null, {
176+
raw: true,
177+
headers: {
178+
'Content-Length': file.length.toString(),
179+
'Content-Type': 'application/pdf',
180+
'Content-Disposition': `attachment; filename="file.pdf"`,
181+
'Cache-Control': 'no-cache'
182+
}
183+
);
184+
185+
return file;
186+
}
187+
```

0 commit comments

Comments
 (0)