- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 175
Custom handler
Objects that will handle parsing request data for chunk detection for every provider.
There are multiple ways how to use custom handler:
1. Set custom handlers in config (in chunk-upload.php, handlers.custom)
If you want to support multiple handlers at one time you can use custom key. If you want to detection super fast, use override key.
'handlers' => [
    // A list of handlers/providers that will be appended to existing list of handlers
    'custom' => [
    	App\MyCustomHandler::class
    ],
    // Overrides the list of handlers - use only what you really want
    'override' => [],
],2. Call HandlerFactory::register(MyClass::class) before using FileReceiver in depedency injection or by using HandlerFactory::classFromRequest
class FileController extends Controller {
	constructor () {
		FileFactory::register(MyCustomHandler::class)
	}
	
	public function uploadFile(FileReceiver $receiver)
	{
		...
	}
	
	public function upload(Request $request) {
    // create the file receiver
    $receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request));
    }
}3. Initalize FileReceiver with a given handler class (third parameter)
class FileController extends Controller {
	public function upload(Request $request) {
    // create the file receiver
    $receiver = new FileReceiver("file", $request, MyCustomHandler::classFromRequest($request));
    }
}See the Contribution section in Readme
Use AbstractHandler for type hint or use a specific handler to se additional methods.
- supported by blueimp-file-upload
- uses the Content-range header with the bytes range
- 
getBytesStart()- returns the starting bytes for current request
- 
getBytesEnd()- returns the ending bytes for current request
- 
getBytesTotal()- returns the total bytes for the file
- Supported by plupload
- uses the chunks numbers from the request
- Supported by resumable.js
- uses the chunks numbers from the request
- Supported by DropZone
- uses the chunks numbers from the request
You can use the automatic detection of the correct handler (provider) by using the HandlerFactory::classFromRequest as
a third parameter when constructing the FileReceiver.
// Exception is thrown if file upload is invalid (size limit, etc)
$receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request));The default fallback class is stored in the HandlerFactory (default SingleUploadHandler::class).
You can change it globally by calling
HandlerFactory::setFallbackHandler(CustomHandler::class)or pass as second parameter when using
HandlerFactory::classFromRequest($request, CustomHandler::class)