Skip to content

Commit 7cb50d4

Browse files
authored
Update README.md (#35)
1 parent 70d8120 commit 7cb50d4

File tree

1 file changed

+70
-26
lines changed

1 file changed

+70
-26
lines changed

README.md

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22

33
Chunk Uploader Package For Laravel
44

5-
<p align="center">
6-
<a href="https://travis-ci.org/LaraCrafts/laravel-chunk-uploader"><img src="https://travis-ci.org/LaraCrafts/laravel-chunk-uploader.svg?branch=master"></a>
7-
<a href="https://packagist.org/packages/laracrafts/laravel-chunk-uploader"><img src="https://poser.pugx.org/laracrafts/laravel-chunk-uploader/downloads"></a>
8-
<a href="https://packagist.org/packages/laracrafts/laravel-chunk-uploader"><img src="https://poser.pugx.org/laracrafts/laravel-chunk-uploader/version"></a>
9-
<a href="https://scrutinizer-ci.com/g/LaraCrafts/laravel-chunk-uploader/"><img src="https://scrutinizer-ci.com/g/LaraCrafts/laravel-chunk-uploader/badges/coverage.png?b=master"></a>
10-
<a href="https://packagist.org/packages/laracrafts/laravel-chunk-uploader"><img src="https://poser.pugx.org/laracrafts/laravel-chunk-uploader/license"></a>
11-
</p>
5+
[![](https://travis-ci.org/LaraCrafts/laravel-chunk-uploader.svg?branch=master)](https://travis-ci.org/LaraCrafts/laravel-chunk-uploader)
6+
[![](https://poser.pugx.org/laracrafts/laravel-chunk-uploader/downloads)](https://packagist.org/packages/laracrafts/laravel-chunk-uploader)
7+
[![](https://poser.pugx.org/laracrafts/laravel-chunk-uploader/version)](https://packagist.org/packages/laracrafts/laravel-chunk-uploader)
8+
[![](https://scrutinizer-ci.com/g/LaraCrafts/laravel-chunk-uploader/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/LaraCrafts/laravel-chunk-uploader/)
9+
[![](https://poser.pugx.org/laracrafts/laravel-chunk-uploader/license)](https://packagist.org/packages/laracrafts/laravel-chunk-uploader)
10+
11+
This package helps integrate a Laravel application with chunk uploader libraries eg.
12+
[DropzoneJS](https://www.dropzonejs.com/) and
13+
[jQuery-File-Upload from blueimp](https://blueimp.github.io/jQuery-File-Upload/).
14+
15+
Uploading a large file in chunks can help reduce risks.
16+
17+
- PHP from 5.3.4 limits the number of concurrent uploads and by uploading a file in one request can limit the
18+
availability of a service. ([max_file_uploads][php-max-file-uploads])
19+
- For security reasons the payload size and the uploadable file size is limited in many systems PHP is not an exception.
20+
([upload_max_filesize][php-upload-max-filesize])
21+
- It can be useful to check the meta information of a file and decline an upload upfront so the user does not have to
22+
wait for minutes or seconds to upload a large file and then receive a message that the file type or mime type is not
23+
allowed.
24+
- Can include resume functionality which means an upload can be continued after a reconnection.
25+
26+
However, there is not a single RFC about chunked uploads and this caused many different implementations. The most mature
27+
project at the moment is [tus](https://tus.io/).
1228

1329
- [Installation](#installation)
1430
- [Requirements](#requirements)
@@ -37,15 +53,21 @@ composer require laracrafts/laravel-chunk-uploader
3753

3854
This package has the following requirements:
3955

40-
- PHP 7.0 or higher
56+
- PHP 7.1 or higher
4157
- Laravel 5.5 or higher
4258

4359
## Usage
4460

45-
The chunk upload handler can be retrieved from the container in two ways:
46-
47-
- Using dependency injection
61+
1. Register a route
62+
```php
63+
Route::any('/my-route', 'MyController@myFunction');
64+
```
65+
2. Retrieve the upload handler. (The chunk upload handler can be retrieved from the container in two ways.)
66+
- Using dependency injection
4867
```php
68+
use Illuminate\Http\Request;
69+
use LaraCrafts\ChunkUploader\UploadHandler;
70+
4971
class MyController extends Controller
5072
{
5173
public function myFunction(Request $request, UploadHandler $handler)
@@ -54,47 +76,67 @@ class MyController extends Controller
5476
}
5577
}
5678
```
57-
- Resolving from the app container
79+
- Resolving from the app container
5880
```php
59-
$handler = app()->make(UploadHandler::class)
60-
$handler->handle($request);
81+
use Illuminate\Http\Request;
82+
use LaraCrafts\ChunkUploader\UploadHandler;
83+
84+
class MyController extends Controller
85+
{
86+
public function myFunction(Request $request)
87+
{
88+
$handler = app()->make(UploadHandler::class);
89+
$handler->handle($request);
90+
}
91+
}
6192
```
6293

6394
The handler exposes the following methods:
6495

6596
Method | Description
66-
---------------|-------------------------------------
97+
---------------|--------------------------
6798
`handle` | Handle the given request
6899

100+
"Handle" is quite vague but there is a reason for that. This library tries to provide more functionality then just
101+
saving the uploaded chunks. It is also adds functionality for resumable uploads which depending on the client side
102+
library can be differ very much. Also, when possible the library gives the opportunity to download the uploaded file.
103+
69104
### Events
70105

71106
Once a file upload is finished a `\LaraCrafts\ChunkUploader\Event\FileUploaded` is triggered. This event contains
72107
the disk and the path of the uploaded file.
108+
[Registering Events & Listeners from Laravel](https://laravel.com/docs/5.8/events#registering-events-and-listeners)
73109

74110
You can also add a `Closure` as the second parameter of the `handle` method to add an inline listener. The listener
75111
is called with the disk and the path of the uploaded file.
76112

113+
```php
114+
$handler->handle($request, function ($disk, $path) {
115+
// Triggered when upload is finished
116+
});
117+
```
118+
77119
### Changing the driver
78120

79121
You can change the default driver by setting a `UPLOAD_DRIVER` environment variable or publishing the
80122
config file and changing it directly.
81123

82124
### Adding your own drivers
83125

84-
Much like Laravels [core components][5], you can add your own drivers for this package. You can do this
85-
by adding the following code to a central place in your application (preferably a service provider).
126+
Much like Laravel's core components, you can add your own drivers for this package. You can do this by adding the
127+
following code to a service provider.
86128

87129
```php
88130
app()->make(UploadManager::class)->extend('my_driver', function () {
89131
return new MyCustomUploadDriver();
90132
});
91133
```
92134

93-
If you are adding a driver you need to extend the `UploadDriver.php` abstract class, for which
94-
you can use the shipped drivers (e.g. `MonolithUploadDriver`) as an example as to how.
135+
If you are adding a driver you need to extend the `\LaraCrafts\ChunkUploader\Driver\UploadDriver` abstract class, for
136+
which you can use the shipped drivers (e.g. `\LaraCrafts\ChunkUploader\Driver\BlueimpUploadDriver`) as an example as to
137+
how.
95138

96-
If you wrote a custom driver that others might find useful, please consider adding it to the package via
97-
a pull request.
139+
If you wrote a custom driver that others might find useful, please consider adding it to the package via a pull request.
98140

99141
## Drivers
100142

@@ -138,14 +180,16 @@ This identifier uses the client session and the original file name to create an
138180

139181
## Contribution
140182

141-
All contributions are welcomed for this project, please refer to the [CONTRIBUTING.md][1] file for more information about contribution guidelines.
183+
All contributions are welcomed for this project, please refer to the [CONTRIBUTING.md][contributing] file for more
184+
information about contribution guidelines.
142185

143186
## License
144187

145188
**Copyright (c) 2019 LaraCrafts.**
146189

147-
This product is licensed under the MIT license, please refer to the [License file][2] for more information.
190+
This product is licensed under the MIT license, please refer to the [License file][license] for more information.
148191

149-
[1]: https://github.com/LaraCrafts/laravel-chunk-uploader/blob/master/CONTRIBUTING.md
150-
[2]: https://github.com/LaraCrafts/laravel-chunk-uploader/blob/master/LICENSE
151-
[5]: https://laravel.com/docs/5.0/extending#managers-and-factories
192+
[contributing]: https://github.com/LaraCrafts/laravel-chunk-uploader/blob/master/CONTRIBUTING.md
193+
[license]: https://github.com/LaraCrafts/laravel-chunk-uploader/blob/master/LICENSE
194+
[php-max-file-uploads]: https://www.php.net/manual/en/ini.core.php#ini.max-file-uploads
195+
[php-upload-max-filesize]: https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize

0 commit comments

Comments
 (0)