Skip to content

Commit

Permalink
updated the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kluska committed Jun 27, 2016
1 parent 311d937 commit 52a618a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
46 changes: 44 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ ___Project in progress___

## Usage

In your own controller create the `FileReceiver`, more in example
In your own controller create the `FileReceiver`, more in example.

## Supports

* Laravel 5+
* [blueimp-file-upload](https://github.com/blueimp/jQuery-File-Upload) - partial support (simple chunked and single upload)

## Basic documentation

### FileReceiver
You must create the file receiver with the file index (in the `Request->file`), the current request and the desired handler class (currently the `ContentRangeUploadHandler::class`)

Then you can use methods:

#### `isUploaded()`
determines if the file object is in the request

####`receive()`
Tries to handle the upload request. If the file is not uploaded, returns false. If the file
is present in the request, it will create the save object.

If the file in the request is chunk, it will create the `ChunkSave` object, otherwise creates the `SingleSave`
which doesnt nothing at this moment.

## Example

### Javascript
Expand Down Expand Up @@ -100,14 +117,39 @@ Add a route to your controller
Route::post('upload', 'UploadController@upload');
```

## Providers/Handlers

### ContentRangeUploadHandler

* supported by blueimp-file-upload
* uses the Content-range header with the bytes range

#### Aditional methods

* `getBytesStart()` - returns the starting bytes for current request
* `getBytesEnd()` - returns the ending bytes for current request
* `getBytesTotal()` - returns the total bytes for the file


## Todo

- [ ] add more providers (like pbupload)
- [ ] add facade for a quick usage with callback and custom response based on the handler
- [ ] cron to delete uncompleted files
- [ ] file per session (to support multiple)
- [ ] add a config with custom storage location
- [ ] add an example project

## Contribution
Are welcome. To add a new provider, just add a new Handler (which extends AbstractHandler), implement the chunk
upload and progress
upload and progress

### Handler class
The basic handler `AbstractHandler` allows to implement own detection of the chunk mode and file naming. Stored in the Handler namespace.

You must implement:

- `getChunkFileName()` - Returns the chunk file name for a storing the tmp file
- `isFirstChunk()` - Checks if the request has first chunk
- `isLastChunk()` - Checks if the current request has the last chunk
- `isChunkedUpload()` - Checks if the current request is chunked upload
11 changes: 6 additions & 5 deletions src/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@ public function __construct(Request $request, UploadedFile $file)
}

/**
* Returns the chunk file name
* Returns the chunk file name for a storing the tmp file
*
* @return string
*/
abstract public function getChunkFileName();

/**
* Returns the first chunk
* Checks if the request has first chunk
*
* @return bool
*/
abstract public function isFirstChunk();

/**
* Returns the chunks count
* Checks if the current request has the last chunk
*
* @return int
* @return bool
*/
abstract public function isLastChunk();

/**
* Returns the current chunk index
* Checks if the current request is chunked upload
*
* @return bool
*/
Expand Down
12 changes: 7 additions & 5 deletions src/Handler/ContentRangeUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,35 @@ public function isChunkedUpload()
}

/**
* @return int
* @return int returns the starting bytes for current request
*/
public function getBytesStart()
{
return $this->bytesStart;
}

/**
* @return int
* @return int returns the ending bytes for current request
*/
public function getBytesEnd()
{
return $this->bytesEnd;
}

/**
* @return int
* @return int returns the total bytes for the file
*/
public function getBytesTotal()
{
return $this->bytesTotal;
}

/**
* Returns the chunk file name
* Returns the chunk file name. Uses the original client name and the total bytes
*
* @return string returns the original name with the part extension
*
* @return string
* @see UploadedFile::getClientOriginalName()
*/
public function getChunkFileName()
{
Expand Down
7 changes: 6 additions & 1 deletion src/Receiver/FileReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ public function isUploaded()
}

/**
* Returns the save instance for handling the uploaded file
* Tries to handle the upload request. If the file is not uploaded, returns false. If the file
* is present in the request, it will create the save object.
*
* If the file in the request is chunk, it will create the `ChunkSave` object, otherwise creates the `SingleSave`
* which doesnt nothing at this moment.
*
* @return bool|AbstractSave
*/
public function receive()
Expand Down

0 comments on commit 52a618a

Please sign in to comment.