美文网首页
阿里开源框架egg.js接收存储图片,并保存到数据库中(二)

阿里开源框架egg.js接收存储图片,并保存到数据库中(二)

作者: 温暖柏林的伤 | 来源:发表于2019-03-18 15:07 被阅读0次

    home.service

    /**

            * 文件上传,接收图片并插入到数据库中

            */

            async upload(params) {

                console.log('333', params);

                const result = await app.mysql.insert('image', params);

                if (result.affectedRows === 1) {

                    const temp_img = await app.mysql.get('image', {

                        id: result.insertId

                    });

                    if (temp_img !== null) {

                        this.config.back_data.code = 200;

                        this.config.back_data.data = {

                            id: temp_img.id,

                            url: temp_img.url,

                        };

                        this.config.back_data.msg = '上传成功';

                    } else {

                        this.config.back_data.code = 400;

                        this.config.back_data.data = {};

                        this.config.back_data.msg = '失败';

                    }

                } else {

                    this.config.back_data.code = 10000;

                    this.config.back_data.data = [];

                    this.config.back_data.msg = '上传失败';

                }

                return this.config.back_data;

            }

    相关文章

      网友评论

          本文标题:阿里开源框架egg.js接收存储图片,并保存到数据库中(二)

          本文链接:https://www.haomeiwen.com/subject/eaovmqtx.html