Why can't files be downloaded by post without form forms?

  1. use the form form method= "POST" to download the file
  2. using a post request submitted by a non-form form to download a file that cannot be parsed is a pile of garbled
  3. is there a solution?
Mar.16,2021

answer for yourself after such a long time. The problem with
is that the result of the fetch request cannot be downloaded, while the form form submission can be downloaded automatically. What we need to solve here is fetch how to download automatically.

there is an object called , while the fetch request is Response object We usually use res.json () , which returns a Promise object parsed into JSON format. Here we need a Blob object, which can be obtained using the res.blob () method.

use URL's createObjectURL and revokeObjectURL to create Blob objects and allow the platform to garbage collect at the right time, respectively. The specific code is as follows:

  https://github.com/johnculvin.

Menu