Skip to content
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

Support injecting custom input-stream path #451

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ public function details(): array
*
* @return int
*/
public function upload(int $totalBytes): int
public function upload(int $totalBytes, ?string $inputFilePath = null): int
{
if ($this->offset === $totalBytes) {
return $this->offset;
}

$input = $this->open($this->getInputStream(), self::READ_BINARY);
$input = $this->open($inputFilePath ?? $this->getInputStream(), self::READ_BINARY);
$output = $this->open($this->getFilePath(), self::APPEND_BINARY);
$key = $this->getKey();

Expand Down
14 changes: 14 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class Request
/** @var HttpRequest */
protected $request;

/**
* Input-stream path
*
* Useful for php-http-servers (e.g. Swoole) that do not support php://input
*
* @var string|null
*/
protected $requestStreamPath = null;

/**
* Request constructor.
*/
Expand Down Expand Up @@ -226,6 +235,11 @@ public function getRequest(): HttpRequest
return $this->request;
}

public function getStreamPath () : ?string
{
return $this->requestStreamPath;
}

/**
* Validate file name.
*
Expand Down
5 changes: 4 additions & 1 deletion src/Tus/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ protected function handlePatch(): HttpResponse

try {
$fileSize = $file->getFileSize();
$offset = $file->setKey($uploadKey)->setChecksum($checksum)->upload($fileSize);
$offset = $file->setKey($uploadKey)->setChecksum($checksum)->upload(
$fileSize,
$this->request->getStreamPath()
);

// If upload is done, verify checksum.
if ($offset === $fileSize) {
Expand Down