Skip to content

Commit

Permalink
support head method
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jun 28, 2021
1 parent 5bbda45 commit bc6539d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/FilePondField.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,20 @@ public function chunk(HTTPRequest $request)
return $response;
}

// location of patch files
$filePath = TEMP_PATH . "/filepond-" . $id;

// FilePond will send a HEAD request to determine which chunks have already been uploaded,
// expecting the file offset of the next expected chunk in the Upload-Offset response header.
if ($method == "HEAD") {
$nextOffset = 0;
while (is_file($filePath . '.patch.' . $nextOffset)) {
$nextOffset++;
}

//TODO: iterate over temp files and check next offset
$response = new HTTPResponse($nextOffset, 200);
$response->addHeader('Content-Type', 'text/plain');
$response->addHeader('Upload-Offset', $nextOffset);
return $response;
}

Expand All @@ -704,14 +710,11 @@ public function chunk(HTTPRequest $request)

// The name of the file being transferred
$uploadName = $request->getHeader('Upload-Name');
// The total size of the file being transferred
// The offset of the chunk being transferred (starts with 0)
$offset = $request->getHeader('Upload-Offset');
// The offset of the chunk being transferred
// The total size of the file being transferred (in bytes)
$length = $request->getHeader('Upload-Length');

// location of patch files
$filePath = TEMP_PATH . "/filepond-" . $id;

// should be numeric values, else exit
if (!is_numeric($offset) || !is_numeric($length)) {
return $this->httpError(400, "Invalid offset or length");
Expand Down

0 comments on commit bc6539d

Please sign in to comment.