I added to 'uploader.onBeforeUploadItem' method code as below:
item.formData['creator'] = {
id: user.id,
name: user.name,
avatar: user.avatar
};
item.formData['content'] = 'value';
And beside of that I add a file from input type file:
<form enctype="multipart/form-data">
<div class="textfield" contenteditable [innerHTML]="content"></div>
<div *ngIf="scope.imageLoaded" class="image-gallery">
<div class="image-preview" [ngStyle]="{'background-image' : 'url(' + scope.addImgPath + ')'}"></div>
</div>
<button (click)="uploader.uploadAll()" class="btn right grey darken-4 send-message" type="submit">Send
<i class="material-icons right">send</i>
</button>
</form>
The problem is, when I try to refere to this values on the backend site, the only property I can get is that file. The other data are not visible there (req.body is undefined):
router.post('/add', (req, res) => {
upload(req, res, (err) => {
let newPost = new Post({
content: req.body.content,
creator: req.body.creator,
post_date: Date.now(),
rate: 0,
users_liked: [],
image: 'http://localhost:3000/uploads/' + req.file.filename
});
Post.addPost(newPost);
});
});
When I check requests by console xhr tab, I see that the only sending data is file. How can I resolve this issue?