Skip to content
Open
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
31 changes: 31 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,37 @@ public function extractAllMeta(): array
return $result;
}

/**
* Set the new value for given key in the metadata from the request header.
* This function will be useful to change metadata on the fly say in the middleware.
*
* @param string $requestedKey
* @param string $newValue
*
* @return string
*/
public function setMeta(string $requestedKey, string $newValue): string
{
$uploadMetaData = $this->request->headers->get('Upload-Metadata');

if (empty($uploadMetaData)) {
return '';
}

$uploadMetaDataChunks = explode(',', $uploadMetaData);

foreach ($uploadMetaDataChunks as $key => $chunk) {
$pieces = explode(' ', trim($chunk));
if ($pieces[0] === $requestedKey) {
$pieces[1] = base64_encode($newValue);
$uploadMetaDataChunks[$key] = implode(' ', $pieces);
break;
}
}

return implode(',', $uploadMetaDataChunks);
}

/**
* Extract partials from header.
*
Expand Down