路径上的Multer Vue js \\

时间:2018-07-30 06:44:49

标签: express vue.js multer

const multer = require('multer');
const Post = require('./models/post')
const path = require('path')
const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, 'uploads/');
    },
    filename: (req, file, cb ) => {
        cb(null, Date.now() + file.fieldname); 
    }
})

const fileFilter = (req, file, cb) => {
    if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
        cb(null, true);
    }else {
        cb(null, false);
    }


}
const upload = multer({
    storage: storage,
    fileFilter,
    limits: {
    fileSize: 1024 * 1024 * 5
}
});

=
app = express();
app.use('uploads',express.static(path.join(__dirname + 'uploads')));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cors());
app.use(morgan('combined'));

mongoose.connect('mongodb://localhost:27017/posts', {useNewUrlParser: true})

在使用邮递员在数据库中创建文件目录时遇到问题。

它显示了postImage \ 812893819.jpeg,我不知道如何处理“ \”。预先谢谢你。

0 个答案:

没有答案