let form = new multiparty.Form({
encoding: "utf-8",
// uploadDir:"public/upload", //
keepExtensions: true //
})
form.parse(ctx.req, function (err, fields, files) {
let data=[]
for(let f of files.file){
//
let date = new Date()
let time = "" + date.getFullYear() + (date.getMonth() + 1) + date.getDate()
let filepath = "project/"+time + "/" + date.getTime()
let fileext = f.originalFilename.split(".").pop()
let upfile = f.path
let newfile = filepath + "." + fileext
//ali-oss
co(function*() {
client.useBucket("p-adm-test")
let result = yield client.put(newfile, upfile)
console.log("!", result.url)
data.push(result.url)
console.log(data)
resolve()
}).catch(function(err) {
console.log(err)
})
}
ctx.response.type = "json"
ctx.response.body = {
errno: 0,
data: data
}
})
as in the above code, I have executed the co function many times. I hope that the result returned each time will be push to the data array, and the data returned to the front end will be the data, after multiple execution, but what if the front end only receives the data, returned for the first time?