我正在使用 loopback
将图像存储到 server
.
我想在保存到服务器之前 modify 文件的 file name .
另外我想在保存之前将其转换为另一个缩略图形式 .
这就是我的表现 .
在客户端
Upload.upload(
{
url: '/api/containers/container_name/upload',
file: file,
fileName: "demoImage.jpg",
//Additional data with file
params:{
orderId: 1,
customerId: 1
}
});
在服务器端我收到查询“params”但没有得到“文件名”
我的存储型号名称是 container
Container.beforeRemote('upload', function(ctx, modelInstance, next) {
//OUPTUTS: {orderId:1, customerId:1]}
console.log(ctx.req.query);
//Now I want to change the File Name of the file.
//But not getting how to do that
next();
})
How to change the File name of the File getting saved at the server?
2 回答
我想到了 .
我们必须在
boot/configure-storage.js
中定义自定义函数 getFileName .假设我的 datasource for
loopback-component-storage
是 presImage .现在假设我的容器模型是
container
.现在将它的图像转换为 Thumbnail size
下载quickthumb
以下是如何将其与环回一起使用 .
此代码直接从Loopback thumbnail view复制
抄袭上面的答案,这个configure-storage允许通过
req.params.filename
显式设置文件名,如果没有提供,则默认为现有名称 .