Want to try umiJS development, encountered problems when uploading files. The page effect should be simple upload file:

However, when I follow the official example, the official example:

Findings:

  1. FormData() does not automatically add the content-Type in the header.

  2. To successfully upload the file, specify the upload type, which is the following code content (the corresponding header content will be automatically added) :

request('/api/v1/some/api', { method: 'post'.data: formData,requestType'form'});Copy the code

Also if your global requesr should comment out the corresponding Content-Type

// Set basic request parameters

const request = extend({

  prefix'http://192.168.20.193:8081/ipsecvpn'.// prefix: '/ipsecvpn',

  timeout8000.headers: {

    // Need to comment out
    // 'Content-Type': 'application/json; charset=utf8',

    // Authorization: localStorage.getItem('Authorization'),

    Authorization'1630395622279 | | 3 | | 00-00-00-00-00-01'.// 'Access-Control-Allow-Origin': '*',}});Copy the code

So, the official documentation sample is missing some code,