Formdata uploads multiple images, why can't it traverse

for(var _img in img_file){           
    formdata.append("file", img_file[_img]);
}
let files = ctx.request.files;
console.log("filesPP+:");console.log(files);
    for(let index in files){
        console.log(index);//file[]
        file = files[index];
        console.log("file---:")
        console.log(file)

console.log (index); / / output file []
and files and files [index] are the same thing
Why?

Apr.03,2021

FormData cannot pass the instance's [] or. Attributes can only be obtained through get
such as

let form = new FormData()
form.append('prop', 1)
console.log(form.prop)//undefined
console.log(form.get('prop'))

if you need to get all the fields, get a pseudo array through api such as keys,values and then manipulate


solved

function upload(files,title){  
    let imgList=[],file,url;
    
    files = files['file'];//
    
    if(files.length){//
        for(let index in files){
            file = files[index];     

            url=`uploads/${title}-${file.name}`;
            fs.createReadStream(file.path).pipe(fs.createWriteStream(url))
        
            imgList.push([index,url]);
        }
    }else{   
        file = files;        
        url=`uploads/${title}-${file.name}`;
        fs.createReadStream(file.path).pipe(fs.createWriteStream(url))
        imgList.push([0,url]);
    }
     
     return imgList;
   
}
exports.add = async(ctx, next)=>{
    let {title,body,tags,category}=ctx.request.body;
    let files = ctx.request.files;//

    let imgList = upload(files,title);

    let post = new Post({
        title,
        body,
        tags,
        category,
        imgList
    })
    let result= await dbHelper.Save(post);
    ctx.response.body = result;    
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaa67c-69744.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaa67c-69744.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?