How to store files with meta data in LoopBack?

前端 未结 7 1735
别跟我提以往
别跟我提以往 2020-11-28 03:05

What I want to do: Have an html form, with a file input inside. When a file is chosen, the file input should upload the file, and get a file id, so when the form is submitte

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 03:41

    Just pass the data as "params" object and at server you can get it as ctx.req.query

    For example

    At client side

    Upload.upload(
    {
        url: '/api/containers/container_name/upload',
        file: file,
        //Additional data with file
        params:{
         orderId: 1, 
         customerId: 1,
         otherImageInfo:[]
        }
    });
    

    At Server side

    Suppose your storage model name is container

    Container.beforeRemote('upload', function(ctx,  modelInstance, next) {
        //OUPTUTS: {orderId:1, customerId:1, otherImageInfo:[]}
        console.log(ctx.req.query); 
        next();
    })
    

提交回复
热议问题