How to return the result when nodejs is uploaded to Aliyun oss file koa2

here I want to use the latest asynchronous way of es6 to achieve, ask for your advice! As I wrote below, I can upload pictures, but I just can"t return the body data. So the result is that the picture has actually been uploaded, but the interface shows 404.

exports.uploadFile = async (ctx,next) => {
let client = new OSS({
    region: "oss-cn-qingdao",
    accessKeyId: "124214124",
    accessKeySecret: "1412414124",
    bucket: "p-144-141244"
})


let form = new formidable.IncomingForm()
    form.parse(ctx.req, function (err, fields, files) {
        client.put(fields.path, files.file.path).then(function (val) {
            // console.log(val.res)
            ctx.body = {
                res: val.res.requestUrls
            }
        }).then(function (val) {
            // console.log(val.res)
            // console.log(val.content.toString())
            ctx.body = {
                res: ""
            }
        })
    })
}


the request has already been returned when the ctx.body, callback cannot be set in the callback. Use async/await.

A similar problem: https://codeshelper.com/q/10.


from your koa2 uploading images using Aliyun oss's nodejs sdk to the recent project using koa for the first time, can I ask you about your specific and complete process? for example, is the js for uploading function in server.js? and then how does the front end operate to get it now is to do a function of uploading pictures to Aliyun, and then I front-end get the image url to Can you see how the specific code is implemented when the formdata form is transmitted to the database? no, no, no. Currently, it is koa2 + mysql

.
Menu