Ich versuche, Bilder mit ne-Datei-Upload zu posten, was gut funktioniert, aber wenn ich versuche, Text hinzuzufügen, wird es nicht mit dem Text gesendet.Verwendung von multer und ng-Datei Upload Wie senden Sie Texte zusammen mit Dateien?
HTML
<h2>Photo Uploads</h2>
<p>This is where photos are uploaded. You can upload a single photo or multiple photos if needed.</p>
<div class="button btn-sm btn btn-default" ngf-select ng-model="files" name="files" ngf-multiple="true">Select</div>
<input type="text" name="event" ng-model="event">
<button type="submit" ng-click="submit()">submit</button>
<pre>{{ event | json }}</pre>
<hr>
Angular - hier die Winkel lädt die Dateien, die in Ordnung ist, aber wenn ich versuche, das Ereignis hinzuzufügen: $ scope.event auf die Daten, die es scheint nicht zu senden.
//FOR MULTIPLE FILES
$scope.uploadFiles = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
Upload.upload({
url: 'api/admin/photos',
data: {'event': $scope.event,files: files[i]}
}).then(function(resp){
$log.info(resp.config.data.event);
$scope.photos.push(resp.data,resp.config.data.event);
//$log.info(resp.data);
$log.info($scope.photos);
getPhotos();
},
function(resp){
console.log('Error status: ' + resp.status);
},
function(evt){
var progressPercentage = parseInt(100.0 * evt.loaded/evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.files.name);
$scope.progress = progressPercentage;
$log.info($scope.progress);
});
}
}
};
NodeJS - müsste ich hier Änderungen am Speicher vornehmen?
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);
});