1const express = require("express");
2const bodyParser = require('body-parser');
3const router = express.Router();
4const path = require('path');
5
6require('dotenv').config();
7require('../../client/src/components/handlers/cloudinary');
8const cloudinary =require("cloudinary");
9var multer = require('multer');
10var storage = multer.memoryStorage();
11var upload = multer({ storage: storage });
12var stream = require('stream');
13
14router.put('/:id', upload.single('image'), function(req, res, next) {
15 var upload_stream = cloudinary.v2.uploader.upload_stream(function(err,image) {
16 res.send(image.secure_url);
17 });
18 console.log(upload_stream);
19 var bufferStream = new stream.PassThrough();
20 bufferStream.end(req.file.buffer);
21 bufferStream.pipe(upload_stream);
22 })
23