Last active
August 31, 2018 16:19
-
-
Save funador/e125f7b1e6bca7247ed976c90cae5282 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
| require('dotenv').config() | |
| const express = require('express') | |
| const cloudinary = require('cloudinary') | |
| const formData = require('express-form-data') | |
| const cors = require('cors') | |
| const { CLIENT_ORIGIN } = require('./config') | |
| const app = express() | |
| cloudinary.config({ | |
| cloud_name: process.env.CLOUD_NAME, | |
| api_key: process.env.API_KEY, | |
| api_secret: process.env.API_SECRET | |
| }) | |
| app.use(cors({ | |
| origin: CLIENT_ORIGIN | |
| })) | |
| app.use(formData.parse()) | |
| app.post('/image-upload', (req, res) => { | |
| const values = Object.values(req.files) | |
| const promises = values.map(image => cloudinary.uploader.upload(image.path)) | |
| Promise | |
| .all(promises) | |
| .then(results => res.json(results)) | |
| }) | |
| app.listen(process.env.PORT || 8080, () => console.log('👍')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment