title: Magento 2 - Custom rest api endpoint for PDF download - net::ERR_HTTP2_PROTOCOL_ERROR 200
body: <ul>
  <li><p>I have created <strong>custom rest api endpoint in magento for downloading pdf file</strong>.</p>
  </li>
  <li><p><strong>When testing it locally:</strong> From separate react JS project I am sending request to that endpoint and <strong>file is downloaded successfuly</strong>. http/1.1 protocol is used (checked in google chrome dev tools, network tab).</p>
  </li>
  <li><p>After deployment to staging servers, when I try to make <strong>request between staging servers from reactJS project to magento2 project</strong>, then upon sending request it takes 30-40 seconds without getting any response and then error is shown in console. There is not anything in the error logs. http2 protocol is used (not sure if that can be a reason for issue).</p>
  </li>
  </ul>
  <blockquote>
  <p>Failed to fetch - net::ERR_HTTP2_PROTOCOL_ERROR 200</p>
  </blockquote>
  <p>Here is the piece of php code for downloading pdf file:</p>
  <pre><code>    ...
      $filename = $outputFileName . time() . '.' . $extension;
      $directoryTmpWrite = $this-&gt;filesystem-&gt;getDirectoryWrite(DirectoryList::TMP);
      $directoryTmpWrite-&gt;writeFile($filename, $fileContent);
  
      return $this-&gt;fileFactory-&gt;create(
          $outputFileName . '.' . $extension,
          [
              'type' =&gt; 'filename',
              'value' =&gt; $filename,
              'rm' =&gt; true,
          ],
          DirectoryList::TMP, //basedir
          'application/octet-stream',
          ''
      );
  </code></pre>