just wondering – is there a way to
presenter to another presenter with form data in the request included?
Specifically a file.
I have two presenters – one uploads an image to backend, second downloads
an image from remote server and then uploads it to backend as well. I do not
want to repeat my code so I decided to get use of first presenter in the second
by passing downloaded image to it. But as the second presenter takes form data
on input, I don't how to deliver the file to it with
forward() – I need something like cURL in the forward() method.
Is it clear and is this possible?
I know I can extract common behaviour to separate class/function/whatever, but that does not fit my case. I have already extracted it and the code left is just condition checking (authenticated, existence etc.) which should reside in the presenter itself.
I could also post request the presenter via standard cURL, but the target (second presenter) is hidden behind authentication so it's no-go.
Thanks for any advice.
Example what I mean:
// PSR way to post image to endpoint $httpClient->sendRequest(new Request('POST', $this->link('//Presenter:action'), , $downloadedImageAsAStream)); // What I am trying to achieve $this->forward('//Presenter:action', [...$optionalParams], $downloadedImageAsAStream); // third parameter does not exist now and probably does not make sense much
Last edited by dakur (2020-06-18 14:10)
@DavidGrudl Yeah, that works, thanks very much!
$this->sendResponse(new \Nette\Application\ForwardResponse( new \Nette\Application\Request('Presenter', 'POST', [...$optionalParams], , [$downloadedImageAsAStream]), ));
Dunno how to specify target action on the presenter, but I don't need it
anyway as I have