Once the question gets answers, its sense cannot be changed, nor can more details be added. In both the cases, the given answers would be invalidated. Questions aren't for an extended back and forth between the user who ask the question and the users who answer. It doesn't work as with forums.
– kiamlaluno♦Oct 6 '18 at 21:16

Ok. I'm sorry. I thought It was the right way to show my changes.
– briastOct 6 '18 at 21:58

The ExportForm class is another example of how to return a file, even if it's a form class. What changes is how the response is used, but how the BinaryFileResponse class is used is still relevant for a controller.
The relevant code is the following one, in ExportForm::submitForm().

Thanks @kiamlaluno. I have tried to rewrite my code with your suggestions, but without success. I have edited the question in order to show you my changes.
– briastOct 6 '18 at 20:08

@briast You just need to return an object of the BinaryFileResponse class. Which hooks the first controller invokes is a different matter, since it is the controller for private files.
– kiamlaluno♦Oct 6 '18 at 21:23

Sorry, but I don't know how to do it. I have tried it in several ways without success. Would you mind if you put me an example. Thanks.
– briastOct 7 '18 at 8:14

At least I found the way. The problem was in javascript side.Now it works. I would like to put the solution, but I'm not sure if I should add it as a new answer or update my question. Thanks.
– briastOct 8 '18 at 6:41

Thanks for your quick answer but It doesn't work. On javascript event, I get XHR.status error 500. In Drupal log I see the next error: Recoverable fatal error: Object of class Drupal\Core\Url could not be converted to string en Drupal\Component\Utility\UrlHelper::isExternal() .
– briastOct 6 '18 at 14:20

I just corrected it. can you re-try, please?
– Cesar MooreOct 6 '18 at 14:31