The axios upload array array contains file objects

1. Describe the problem
requirements as above, and the backend interface needs my post format as follows:

{
    "type": "***",
    "list": [
        {
            "filename": "***",
            "filedata": File
        }
    ]
}

2. I have tried
I directly set content-type to application/x-www-form-urlencoded, but the data sent is not what the backend wants, so instead, multipart/form-data, finds that it can not correctly transmit data of type File
3. So when using axios, what should we do when we encounter this type of parameter passing?

Jan.24,2022

pass it through the form, such as

var form = new FormData();
//
//
form.append('filekey',files);
axios.post(url,form).then((data) => { // })

get the file source through the form, ha, how do you get the uploaded content!


I suggest we do it separately. First of all, the object you passed used to be [obj obj], but not json serialization, so that all backend receivers are like this, and the file type will be killed when json serialization, and the type does not match.
you can adjust the parameters with the backend, leaving a special field to connect with the file parameters, and the others are json data communication.
is probably
let params = new FormData ();
params.append ('file', this.simpleVideoFile); / / it doesn't matter if it is a file collection array, or it can be passed to the same field several times. The backend can distinguish it. You have to negotiate
params.append (' param', JSON.stringify (other parameters))

.
Menu