栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

修改从loopback-component-storage获得的图像

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

修改从loopback-component-storage获得的图像

我想到了。

我们必须定义一个自定义函数 的getFileName

boot/configure-storage.js

假设我的 数据源

loopback-component-storage
presImage

服务器/引导/配置存储.js

module.exports = function(app) {    //Function for checking the file type..    app.dataSources.presImage.connector.getFilename = function(file, req, res) {        //First checking the file type..        var pattern = /^image/.+$/;        var value = pattern.test(file.type);        if(value ){ var fileExtension = file.name.split('.').pop(); var container = file.container; var time = new Date().getTime(); var query = req.query; var customerId = query.customerId; var orderId    = query.orderId; //Now preparing the file name.. //customerId_time_orderId.extension var NewFileName = '' + customerId + '_' + time + '_' + orderId + '.' + fileExtension; //And the file name will be saved as defined.. return NewFileName;        }        else{ throw "FileTypeError: only File of Image type is accepted.";        }    };}

common / models / container.js

现在假设我的容器模型是

container

module.exports = function(Container) {    Container.afterRemote('upload', function(ctx,  modelInstance, next) {      var files = ctx.result.result.files.file;      for(var i=0; i<files.length; i++){        var ModifiedfileName = files[i].name;        console.log(ModifiedfileName) //outputs the modified file name.      } //for loop      next();    }); //afterRemote..};

现在将其转换为 缩略图大小

下载quickthumb

这是将其与环回一起使用的方法。

此代码直接从“
回送”缩略图视图复制

common / models / container.js

module.exports = function(Container) {    var qt = require('quickthumb');    Container.afterRemote('upload', function(ctx, res, next) {        var file = res.result.files.file[0];        var file_path = "./server/storage/" + file.container + "/" + file.name;        var file_thumb_path = "./server/storage/" + file.container + "/thumb/" + file.name;        qt.convert({ src: file_path, dst: file_thumb_path, width: 100        }, function (err, path) {        });        next();    });};


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号