Created
June 26, 2017 21:40
-
-
Save abachuk/5c13a53de1c3f5cd67c47adfdfa76cc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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