Modify image obtained from loopback-component-storage

前端 未结 2 1222
鱼传尺愫
鱼传尺愫 2020-12-14 22:37

I am using loopback for storing Image to the server.

I want to modify the file name of the file before ge

2条回答
  •  青春惊慌失措
    2020-12-14 23:00

    Piggybacking on the answer above, this configure-storage enables the file name to be set explicitly via req.params.filename and to default to the existing name if none is provided.

    configure-storage.js

    module.exports = function(app) {
    
    //Function for checking the file type..
        app.dataSources.storage.connector.getFilename = function(file, req, ignoreRes) {
    
            if (!req.params.filename) {
                return file.name
            }
    
            var fileExtension = file.name.split('.').pop()
            return req.params.filename + '.' + fileExtension
    
        };
    }
    

提交回复
热议问题