@@ -214,6 +214,62 @@ public function upload(Request $request) {
214214}
215215```
216216
217+ ##### Usage with multiple files in one Request
218+
219+ ``` php
220+ /**
221+ * Handles the file upload
222+ *
223+ * @param Request $request
224+ *
225+ * @param Int $fileIndex
226+ *
227+ * @return \Illuminate\Http\JsonResponse
228+ *
229+ * @throws UploadMissingFileException
230+ */
231+ public function upload(Request $request) {
232+
233+ // Response for the files - completed and uncompleted
234+ $files = [];
235+
236+ // Get array of files from request
237+ $files = $request->file('files');
238+
239+ if (!is_array($files)) {
240+ throw new UploadMissingFileException();
241+ }
242+
243+ // Loop sent files
244+ foreach ($files as $file) {
245+ if ($receiver->isUploaded()) {
246+ // receive the file
247+ $save = $receiver->receive();
248+
249+ // check if the upload has finished (in chunk mode it will send smaller files)
250+ if ($save->isFinished()) {
251+ // save the file and return any response you need
252+ $files[] = $this->saveFile($save->getFile());
253+ } else {
254+ // we are in chunk mode, lets send the current progress
255+
256+ /** @var ContentRangeUploadHandler $handler */
257+ $handler = $save->handler();
258+
259+ // Add the completed file
260+ $files[] = [
261+ "start" => $handler->getBytesStart(),
262+ "end" => $handler->getBytesEnd(),
263+ "total" => $handler->getBytesTotal(),
264+ "finished" => false
265+ ];
266+ }
267+ }
268+ }
269+
270+ return response()->json($files);
271+ }
272+ ```
217273
218274#### Route
219275Add a route to your controller
@@ -334,4 +390,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes. All contri
334390was written by [ Martin Kluska] ( http://kluska.cz ) and is released under the
335391[ MIT License] ( LICENSE.md ) .
336392
337- Copyright (c) 2016 Martin Kluska
393+ Copyright (c) 2016 Martin Kluska
0 commit comments