jeudi 6 août 2015

failed uploading file using Express4 and multer

I am trying to do the image ajax upload using Express4 and multer, but it doesn't work

here is my request screenshot

enter image description here

and here is the server script

var multer  = require('multer');
var upload = multer({ dest: 'uploads/' });
var router = express.Router();

router.route('/upload')
  .post(upload.single('file'), function(req, res) {
    console.log(req.file);
    //req.file is undefined
});

updated client code:

import Ember from 'ember';

export default Ember.TextField.extend({
  type: 'file',
  change: function(e) {
    var inputFiles = e.target.files;
    var inputFile = inputFiles[0];
    var formData = new FormData();
    formData.append('file', inputFile);
    Ember.$.ajax({
      type: 'POST',
      url: '/upload',
      data: formData,
      cache: false,
      contentType: false,
      processData: false,
      success: function(data) {
        console.log(data);
      },
      error: function(err) {
        console.error(err)
      }
    })
  }
});




Aucun commentaire:

Enregistrer un commentaire