Angularjs 使用multer和ng文件上载,如何随文件一起发送文本?

Angularjs 使用multer和ng文件上载,如何随文件一起发送文本?,angularjs,node.js,ng-file-upload,Angularjs,Node.js,Ng File Upload,我正在尝试使用ne文件上传发布图像,这很好,但当我尝试向其中添加文本时,它不会随文本一起发送 HTML 照片上传 这是上传照片的地方。如果需要,您可以上载一张或多张照片 挑选 提交 {{event}json} Angular-Angular正在上载文件,这很好,但当我尝试将事件:$scope.event添加到数据时,它似乎没有发送它 var storage = multer.diskStorage({ destination: function (req, file, cb) {

我正在尝试使用ne文件上传发布图像,这很好,但当我尝试向其中添加文本时,它不会随文本一起发送

HTML

照片上传
这是上传照片的地方。如果需要,您可以上载一张或多张照片

挑选 提交 {{event}json}
Angular-Angular正在上载文件,这很好,但当我尝试将事件:$scope.event添加到数据时,它似乎没有发送它

    var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'public/img')
  },
  filename: function (req, file, cb) {
    //cb(null, file.originalname + '-' + Date.now())
    console.log(req.body);
    req(req.body);
    cb(null, file.originalname)
  }
});

var upload = multer({ storage: storage });



//upload photos
apiRoutes.post('/admin/photos',upload.array('files',20),function(req,res){

    console.log(req.body);

    for (var i = 0; i < req.files.length; i++) {
        console.log(req.files[i].originalname);



        //this is to see the other section of photos
        console.log('the real deal');

         var photo = new Photos({
        url: req.files[i].filename,
        name: req.files[i].filename,

        //event: req.body
        });

      photo.save(function(err,docs){
        if(err) throw err;

      });
    };


    res.json(req.files);

});
//用于多个文件
$scope.uploadFiles=函数(文件){
if(files&&files.length){
对于(var i=0;i
NodeJS-我需要在这里更改存储吗

Specify the file and optional data to be sent to the server.
Each field including nested objects will be sent as a form data multipart.
Samples: {pic: file, username: username}
{files: files, otherInfo: {id: id, person: person,...}} multiple files (html5)
{profiles: {[{pic: file1, username: username1}, {pic: file2, username: username2}]} nested array multiple files (html5)
{file: file, info: Upload.json({id: id, name: name, ...})} send fields as json string
{file: file, info: Upload.jsonBlob({id: id, name: name, ...})} send fields as json blob, 'application/json' content_type
{picFile: Upload.rename(file, 'profile.jpg'), title: title} send file with picFile key and profile.jpg file name*/
*data: {key: file, otherInfo: uploadInfo},/*
var storage=multer.diskStorage({
目标:功能(请求、文件、cb){
cb(空,“公共/img”)
},
文件名:函数(请求、文件、cb){
//cb(null,file.originalname+'-'+Date.now())
控制台日志(请求主体);
请求(请求正文);
cb(null,file.originalname)
}
});
var upload=multer({storage:storage});
//上传照片
apiRoutes.post('/admin/photos',upload.array('files',20),函数(req,res){
控制台日志(请求主体);
对于(变量i=0;i
嗨,我和你一样遇到了麻烦。
解决方法很简单
在gitgub中,开发者说

$scope.submit = function()
  {
      Upload.upload({
          url: serverip+'/make_item',
          data: {file: $scope.file,asd:"asd"}
      }).then(function (data) {
          console.log(data);
      });
    };

因此,您只需将文本数据放入ng文件json请求中

这是我的箱子

headers: 
   { host: '52.78.68.136',
     connection: 'keep-alive',
     'content-length': '4366',
     accept: 'application/json, text/plain, */*',
     origin: 'null',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
     authorization: 'file',
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryIIep9fVUqmCV1Bg7',
     'accept-encoding': 'gzip, deflate',
     'accept-language': 'ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4' },
(我只是把asd放在测试中)

结果是这样的

我把重要的数据放在req中

file: 
   { fieldname: 'file',
     originalname: 'KakaoTalk_20160719_004110244.jpg',
     encoding: '7bit',
     mimetype: 'image/jpeg',
     destination: './public/img/item_img',
     filename: '1471176191895.jpg',
     path: 'public/img/item_img/1471176191895.jpg',
     size: 4067 } }
这是req.file

body: { asd: 'asd' },
最后,请求正文

它起作用了

请问我其他问题。

嗨,我和你一样也遇到了麻烦。
解决方法很简单
在gitgub中,开发者说

$scope.submit = function()
  {
      Upload.upload({
          url: serverip+'/make_item',
          data: {file: $scope.file,asd:"asd"}
      }).then(function (data) {
          console.log(data);
      });
    };

因此,您只需将文本数据放入ng文件json请求中

这是我的箱子

headers: 
   { host: '52.78.68.136',
     connection: 'keep-alive',
     'content-length': '4366',
     accept: 'application/json, text/plain, */*',
     origin: 'null',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
     authorization: 'file',
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryIIep9fVUqmCV1Bg7',
     'accept-encoding': 'gzip, deflate',
     'accept-language': 'ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4' },
(我只是把asd放在测试中)

结果是这样的

我把重要的数据放在req中

file: 
   { fieldname: 'file',
     originalname: 'KakaoTalk_20160719_004110244.jpg',
     encoding: '7bit',
     mimetype: 'image/jpeg',
     destination: './public/img/item_img',
     filename: '1471176191895.jpg',
     path: 'public/img/item_img/1471176191895.jpg',
     size: 4067 } }
这是req.file

body: { asd: 'asd' },
最后,请求正文

它起作用了
请问我其他问题