Hey @mficzel,
thanks a lot! I’m now a step ahead (i hope) and at least the file upload is interrupted.
I actually have no clue what you intend with the second if that checks for “HEAD” requests but the last line is fine again and will allow all requests without files be processed normally.
That was just test where i wanted to check with curl if “something” works
Currently my code looks like this:
<?php
namespace Vendor\Intercept\Http;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
/*
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
*/
use Psr\Log\LoggerInterface;
/**
* A sample HTTP middleware that adds a custom header to the response
*/
final class InterceptionMiddleware implements MiddlewareInterface {
public function injectLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
{
// Check the the request type
if ($request->getMethod() === 'POST' && !empty($request->getUploadedFiles())) {
$this->logger->debug('av - post request with non empty uploaded files');
parse_str($request->getUri()->getQuery(), $queryArguments);
if (!isset($queryArguments['upload'])) {
$this->logger->debug('av - query argument is upload');
$uploadedFiles = $request->getUploadedFiles();
foreach ($uploadedFiles as $uploadedFile) {
$this->logger->debug('av - started the iteration');
$fileContents = $uploadedFile->getStream()->getContents();
$this->logger->debug('av - the iteration worked');
}
}
$this->logger->debug('av - whatever happens here');
return new Response(200, ['Content-Type' => 'application/json'], json_encode(['success' => true]));
}
$this->logger->debug('av - nothing to do');
return $next->handle($request);
}
}
I’m going step by step, as this is the very first time i’m investing time into that new topic. At first i want to have the file, and later think about what i do with it, and how i can send it to an API or Service that scans the file (no clue about that yet actually )
But it seems like currently i fail using the getStream()
method. Because when i’m using the above code, read the System_Development.log
i do see the following:
tail -f System_Development.log | grep av
24-03-21 12:58:50 19922 DEBUG av - post request with non empty uploaded files
24-03-21 12:58:50 19922 DEBUG av - query argument is upload
24-03-21 12:58:50 19922 DEBUG av - started the iteration
24-03-21 12:58:55 19922 DEBUG av - nothing to do
And also, not using grep the following exception is thrown:
Exception in line 74 of /app/Data/Temporary/Development/SubContextDocker/Cache/Code/Flow_Object_Classes/Neos_Flow_Http_Middleware_MiddlewaresChain.php: Call to a member function getStream() on array - See also: 20240321125850318b25.txt
So again i’m stuck, and i’m trying to find out how to use the methods of Psr\Http\Message\UploadedFileInterface, if that’s even the right approach.