1 Upload files using HTTP

                const formData = new FormData();
                formData.append('file', params.file);
                this.$axios({
                    method: 'post'.url: url, // Request an address
                    data: formData,
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    },
                }).then(data= > {
Copy the code

Multiple file uploads are supported, along with other parameters, such as multipart/form-data in HTTP requests, which processes the form’s data into a single message, grouped by labels and separated by delimiters. You can upload both key-value pairs and files. When the uploaded field is a file, the content-Type is used to name the file Type. Content-disposition, which specifies some information about the field;

Because of boundary isolation, multipart/form-data can upload both files and key-value pairs. Multipart /form-data uses key-value pairs, so it can upload multiple files.

2 binary

Content-type :application/octet-stream: only binary data can be uploaded. It is usually used to upload files. There are no keys, so only one file can be uploaded at a time.

Reference address blog.csdn.net/qq_33706382…

The download file

 this.$axios({
          method: 'get'.url: url, // Request an address
          headers: {
            'Content-Type': 'multipart/form-data'
          },
          responseType: 'blob' // Indicates the type of data returned by the server
        }).then(data= > {
          const content = data.data;
          const blob = new Blob([content])
          const fileName = 'template. XLSX'
          if ('download' in document.createElement('a')) { // Non-IE download
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // Release the URL object
            document.body.removeChild(elink)
          } else { / / ie 10 + downloads
            navigator.msSaveBlob(blob, fileName)
          }
Copy the code