How to submit post data with ng2 file upload in angular 2? Form values and uploaded docs should be bundled into single object and sent to API. #690
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?
The controller should receive form values and documents uploaded objects.
I tried with
const formData = new FormData();then append form data and uploader object to formData. formData should be an object containing form values and files uploaded.FormData object is sent to API where form values and files are accessed seperately.Refererred :http://stackoverflow.com/questions/38502687/how-to-submit-post-data-with-ng2-file-upload-in-angular-2
You can send extra parameters like this in formData:-
var uploader = new FileUploader({
url: "user/filesupload",
type: 'post',
formData: [{master: master, user_id: $scope.current_instance, folder_id: $scope.parent_id}],
headers: {
'Authorization': 'Basic 123445'
},
});
Add form data as additionalParameter, see FileUploaderOptions interface:
additionalParameter?: { [key: string]: any; }like so:
document.setOptions({ headers: [{name: 'name', value: 'value'}], additionalParameter: { documentType: 'document type' }more to read: https://github.com/valor-software/ng2-file-upload/blob/development/src/file-upload/file-uploader.class.ts#L293
Hope it helps.
See @msfanous post here for a working example of how to add form data