title: View blob file using react
body: <p>I want to display a blob file with React. I am loading this from MySQL database beforehand and trying to display the file. Unfortunately I'am unable to do so, at the end I am always geting an error that the document could not be loaded (see image)</p>
  <p>My function that should do that:</p>
  <pre><code>function download(dokument) {
   const file = new Blob([dokument], { type: &quot;application/pdf&quot; });
  
   //Build a URL from the file
   const fileURL = URL.createObjectURL(file);
   //Open the URL on new Window
   window.open(fileURL);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/U7Oe5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U7Oe5.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/MhKcP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MhKcP.png" alt="enter image description here" /></a></p>
  <p><strong><strong>UPDATE</strong></strong>*</p>
  <p>The file is a PDF file. The file is stored as a byte[] in MySQL using an entity and Spring Boot</p>
  <pre><code> @PostMapping(&quot;/upload&quot;)
  public void uploadFile(@RequestParam(&quot;file&quot;) MultipartFile file, RedirectAttributes redirectAttributes,
          HttpServletRequest req) {
  
      if (file.isEmpty()) {
          redirectAttributes.addFlashAttribute(&quot;message&quot;, &quot;Please select a file to upload&quot;);
          return;
      }
  
      try {
  
          String titel = req.getParameter(&quot;titel&quot;);
          String status = req.getParameter(&quot;status&quot;);
          String zugewiesenAn = req.getParameter(&quot;zugewiesenAn&quot;);
  
          byte[] bytes = file.getBytes();
  
          Dokumente dokument = new Dokumente();
          dokument.setName(titel);
          dokument.setGesehen(0);
          dokument.setStatus(status);
          dokument.setZugewiesen(zugewiesenAn);
          dokument.setDatum(new Date());
          dokument.setUploadVon(&quot;Hans Maier&quot;);
          dokument.setDokument(bytes);
          dokument.setDokumentenTyp(file.getContentType());
  
          dokumentRepo.save(dokument);
  
          System.out.println(&quot;success&quot;);
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>