Monday, 15 May 2017

Rename uploaded images using MULTER

I am uploading the images using multer. They all are given random names (dec93b9f333c7a731723b06ce73c0bbc.jpg), which is very bad for SEO... Can you guys help me out, how to save the images with the pattern: 'fixed-name'+'random-name'.extension. Then at least part of the file would be readable for the google. Thanks!

app.set('images', '/var/www/images');
app.use(app.get('images'), express.static(app.get('images')));
var multerForImage = multer({
    dest: app.get('images'),
    onParseStart: function (file) {
        console.log("Started parsing file stream", file);
    },
    onFileUploadStart: function (file) {
        console.log('File recieved: ', file.originalname);
    },
    onFileUploadComplete: function (file, req, res) {
        console.log("File upload complete");
        var path = app.get('images') + "/" + file.name;
        var user = req.session.user;
        res.json({
            success: true,
            data: path
        });

    },
    onFileUploadData: function (file, data, req, res) {
        console.log('Data recieved for file upload');
    },
    onParseEnd: function (req, next) {
        console.log("Parsing data end for file upload");
    }
});



via igor

No comments:

Post a Comment