Created
January 14, 2020 03:51
-
-
Save harrisonmalone/8a410808b0c2cf6d3a8c3539128a0bc1 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
| 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() | |
| }) | |
| }) |
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
| const multer = require('multer') | |
| const storage = multer.memoryStorage() | |
| const upload = multer({storage: storage }) | |
| const form = [ | |
| {name: 'name'}, | |
| {name: 'image'} | |
| ] | |
| module.exports = upload.fields(form) |
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
| 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, | |
| } |
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
| 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