“Unggah file Multer Express” Kode Jawaban

Unggah file Multer Express

const multer  = require('multer')
const upload = multer({ dest: './public/data/uploads/' })
app.post('/stats', upload.single('uploaded_file'), function (req, res) {
   // req.file is the name of your file in the form above, here 'uploaded_file'
   // req.body will hold the text fields, if there were any 
   console.log(req.file, req.body)
});
Jittery Jellyfish

Unggah file menggunakan Multer ExpressJS

var express = require('express');
var router = express.Router();
const multer  = require('multer');

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
})
const upload = multer({storage: storage})

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/profile', upload.single('avatar'), function (req, res, next) {
})


module.exports = router;
Javasper

Jawaban yang mirip dengan “Unggah file Multer Express”

Pertanyaan yang mirip dengan “Unggah file Multer Express”

Lebih banyak jawaban terkait untuk “Unggah file Multer Express” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya