formData excluding file is undefined on the backend side #1064
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
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:
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):
When I check requests by console xhr tab, I see that the only sending data is file. How can I resolve this issue?
Hi, had the same problem today. From looking through the source code it looks like
item.formDatais not referenced when sending the file (or anywhere else in the code).I did get this working by overriding the
onBuildItemFormmethod.The solution is:
Set the override in the constructor
Then add the class method
On the web-server end I can now see the siteId parameter.
In your case, change the code slightly with the desired key/value pairs, creator and content.
@vitamink Thanks for this. Now I can add the form data I need :)
Add form data as additionalParameter in FileUploaderOptions works for me
Reference: https://github.com/valor-software/ng2-file-upload/issues/924