我想到了。
我们必须定义一个自定义函数 的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(); });};


