Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created January 14, 2020 03:51
Show Gist options
  • Select an option

  • Save harrisonmalone/8a410808b0c2cf6d3a8c3539128a0bc1 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/8a410808b0c2cf6d3a8c3539128a0bc1 to your computer and use it in GitHub Desktop.
const request = require('supertest')
const app = require('../app')
test('image passes through successfully', async () => {
await request(app)
.post('/products')
.attach('image', 'tests/images/dog.jpg')
.field('name', 'harrison')
.then((response) => {
console.log(response.text)
expect(response.text).toBeTruthy()
})
})
const multer = require('multer')
const storage = multer.memoryStorage()
const upload = multer({storage: storage })
const form = [
{name: 'name'},
{name: 'image'}
]
module.exports = upload.fields(form)
const index = (req, res) => {
const { image } = req.files
const { name } = req.body
console.log(name)
console.log(image[0])
// s3 stuff
// handling the file buffer
res.send('api works')
}
module.exports = {
index,
}
const express = require('express')
const router = express.Router()
const multer = require('../middleware/multer-middleware')
const { index } = require('../controllers/products-controller')
router.post('/', multer, index)
module.exports = router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment