File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,35 @@ Body:
138138* ` $response->stream(io.streams.InputStream $in[, int $size]) ` will stream a response
139139* ` $response->body(string $bytes) ` will write the given raw bytes to the response
140140
141+ Asynchronous invocation
142+ -----------------------
143+
144+ The following code will run the upload function asynchronously, continuing to serve requests while file contents are being transmitted.
145+
146+ ``` php
147+ use io\Folder;
148+ use web\rest\{Async, Post, Resource, Response};
149+
150+ #[Resource('/api')]
151+ class Uploads {
152+ public function __construct(private Folder $folder) { }
153+
154+ #[Post('/files')]
155+ public function upload(#[Request] $req) {
156+ return new Async(function() use($req) {
157+ if ($multipart= $req->multipart()) {
158+
159+ foreach ($multipart->files() as $file) {
160+ yield from $file->transmit($this->folder);
161+ }
162+ }
163+
164+ return Response::ok();
165+ });
166+ }
167+ }
168+ ```
169+
141170See also
142171--------
143172
You can’t perform that action at this time.
0 commit comments