Angularjs 未使用ng文件上载和multer上载图像
我正在尝试使用Angularjs 未使用ng文件上载和multer上载图像,angularjs,node.js,express,multer,ng-file-upload,Angularjs,Node.js,Express,Multer,Ng File Upload,我正在尝试使用ng file upload和multer进行文件上传。我的代码目前看起来像这样 HTML文件 <form class="form-inline" ng-submit="startUpload()"> <div class="form-group"> <fieldset> <label for="city" class="hidden"></label> <input id="
ng file upload
和multer
进行文件上传。我的代码目前看起来像这样
HTML文件
<form class="form-inline" ng-submit="startUpload()">
<div class="form-group">
<fieldset>
<label for="city" class="hidden"></label>
<input id="city" class="form-control" type="text" name="city"
ng-model="city" placeholder="City" />
<label for="description" class="hidden"></label>
<input id="description" class="form-control" type="text" name="description"
ng-model="description" placeholder="Description" />
<label for="images" class="hidden"></label>
<input id="images" class="form-control" type="file" name="images"
placeholder="Images" accept="image/*"
ngf-select="uploadFiles($files, $invalidFiles)" />
<input class="btn btn-custom btn-submit" type="submit" value="Upload">
</fieldset>
</div>
后端API
var multer = require('multer');
var upload = multer({ dest : 'source/public/assets/img/test/' });
app.post(versionUrl + '/create-entry', upload.array('images'), function(req, res, next) {
console.log(req.body) // this contains all text data
console.log(req.files) // this is always an empty array
});
因为这是我第一次做这样的事情,所以我对它不起作用感到非常沮丧。互联网上有很多例子,提供了完全相同的代码——但这一个对我来说并不适用
我很乐意接受所有建议,帮助我解决这个问题。您需要在
数据中设置图像:图像
:
var data = {
location: $scope.city,
title: 'test title',
description: $scope.description,
images: images
};
Upload.upload({
url: uploadUrl,
arrayKey: '',
data: data,
});
您需要在数据
对象中设置图像:图像
:
var data = {
location: $scope.city,
title: 'test title',
description: $scope.description,
images: images
};
Upload.upload({
url: uploadUrl,
arrayKey: '',
data: data,
});
嗯,这似乎现在起作用了。您能解释一下为什么我需要将图像存储在“图像”字段中吗?我想我必须使用“文件”字段。文件
不是上载选项。上载因此文件:图像
将被忽略。好吧,这似乎现在可以工作了。您能解释一下为什么我需要将图像存储在“图像”字段中吗?我想我必须使用“文件”字段。文件
不是上载选项。上载因此文件:图像
将被忽略。