Skip to content

Handler for simple-uploader #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Handler/ChunksInRequestSimpleUploadHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Pion\Laravel\ChunkUpload\Handler;


/**
* Class ChunksInRequestSimpleUploadHandler
*
* Upload receiver that detects the content range from he request value - chunks
* Works with:
* - simple-uploader: https://github.com/simple-uploader
*
* @package Pion\Laravel\ChunkUpload\Handler
*/
class ChunksInRequestSimpleUploadHandler extends ChunksInRequestUploadHandler
{
/**
* Key for number of sending chunk
* @static string
*/
protected const KEY_CHUNK_NUMBER = 'chunkNumber';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove please too :)


/**
* Key for number of all chunks
* @static string
*/
protected const KEY_ALL_CHUNKS = 'totalChunks';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove please too :)

}
18 changes: 15 additions & 3 deletions src/Handler/ChunksInRequestUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
*/
class ChunksInRequestUploadHandler extends AbstractHandler
{
/**
* Key for number of sending chunk
* @static string
*/
const KEY_CHUNK_NUMBER = 'chunk';

/**
* Key for number of all chunks
* @static string
*/
const KEY_ALL_CHUNKS = 'chunks';

/**
* The current chunk progress
* @var int
Expand Down Expand Up @@ -56,7 +68,7 @@ public function __construct(Request $request, $file, $config)
*/
public static function canBeUsedForRequest(Request $request)
{
return $request->has('chunk') && $request->has('chunks');
return $request->has(static::KEY_CHUNK_NUMBER) && $request->has(static::KEY_ALL_CHUNKS);
}

/**
Expand All @@ -82,7 +94,7 @@ public function startSaving($chunkStorage)
protected function getCurrentChunkFromRequest(Request $request)
{
// the chunk is indexed from zero (for 5 chunks: 0,1,2,3,4)
return intval($request->get('chunk')) + 1;
return intval($request->get(static::KEY_CHUNK_NUMBER)) + 1;
}

/**
Expand All @@ -94,7 +106,7 @@ protected function getCurrentChunkFromRequest(Request $request)
*/
protected function getTotalChunksFromRequest(Request $request)
{
return intval($request->get("chunks"));
return intval($request->get(static::KEY_ALL_CHUNKS));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Handler/HandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class HandlerFactory
ContentRangeUploadHandler::class,
ChunksInRequestUploadHandler::class,
ResumableJSUploadHandler::class,
DropZoneUploadHandler::class
DropZoneUploadHandler::class,
ChunksInRequestSimpleUploadHandler::class
);

/**
Expand Down