Skip to content

Instantly share code, notes, and snippets.

@abachuk
Created June 26, 2017 21:40
Show Gist options
  • Save abachuk/5c13a53de1c3f5cd67c47adfdfa76cc7 to your computer and use it in GitHub Desktop.
Save abachuk/5c13a53de1c3f5cd67c47adfdfa76cc7 to your computer and use it in GitHub Desktop.
import axios from 'axios';
import cloudinary from 'cloudinary';
export default function fileUploadMiddleware(req, res) {
cloudinary.uploader.upload_stream((result) => {
axios({
url: '/api/upload', //API endpoint that needs file URL from CDN
method: 'post',
data: {
url: result.secure_url,
name: req.body.name,
description: req.body.description,
},
}).then((response) => {
res.status(200).json(response.data.data);
}).catch((error) => {
res.status(500).json(error.response.data);
});
}).end(req.file.buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment