Correct way of adding additionalParamater #673
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?
I try to use additionalParameters to upload more information to my MVC5 Web Api.
this.uploaderOptions.additionalParameter = { 'app': 'fibi', 'user': 'me' };this.uploader.setOptions(this.uploaderOptions);But my payload looks a bit odd and my web api method crashes when I add the extra parameters.
------WebKitFormBoundaryxXDzjn8HDfr3z96B
Content-Disposition: form-data; name="file"; filename="PORTF_test.DAT"
Content-Type: application/octet-stream
------WebKitFormBoundaryxXDzjn8HDfr3z96B
Content-Disposition: form-data; name="app"
fibi
------WebKitFormBoundaryxXDzjn8HDfr3z96B
Content-Disposition: form-data; name="user"
me
------WebKitFormBoundaryxXDzjn8HDfr3z96B--
Why aren't my parameters in the first section like filename?
Thankful for any help.
I have the question about how to use additionalParameter as well, has anyone used additionalParameter and it's working?? Thanks
@weishiny It work, my backend is expressjs and I just do
And just get it in the body
console.log(req.body.hello);@weishiny I used an alternative approach since I did not get it to work with additionalParameter.
In my angular code I added my own headers
and then I extracted those inside my MVC5 WebApi
Works perfectly for me.
@hakalb and @hong-duc ,
thanks you guys a lot, I will try it when I implement the upload file function.
@hakalb
Do you have a working plunker of your additional parameters setup so I can see how it all connects?
Thanks
Andy
@stephenad No sorry, I only got in my project.
@hakalb ,
No problem, this is what I have, can you see how I can output my values to the table:
I declared my file uploader:
public uploaderOptions:FileUploader = new FileUploader({url: URL});Then I have set the items similar to what you have above:
this.uploader.options.headers =[]; this.uploader.options.headers.push({ name: 'renyear', value: this.dSelectedRenYear }); this.uploader.options.headers.push({ name: 'RenClassification', value: this.dSelectedBusClass }); this.uploader.options.headers.push({ name: 'dBusClass', value: this.dSelectedClassification }); this.uploader.setOptions(this.uploader);I can then see in my console the values I push into the headers array, but in my code where I have the table my for loop looks at the uploader.queue so I do not know how to get my values out.
Below html where i am trying to output the table I have the following:
`
//
Name
Renewal Year
Business Class
Renewal Classification
Size
Progress
Status
Actions
<tr *ngFor="let item of this.uploader.queue">
{{ item?.file?.name }}
{{ item?.options?.headers[0].value }}
{{ item?.options?.headers[1].value }}
{{ item?.options?.headers[2].value }}
{{ item?.file?.size/1024 | number:'.2' }} KB
...
`
This is what I can seen when I do a console.dir of this.uploader
headers : Array(3) 0 : {name: "renyear", value: "2016"} 1 : {name: "RenClassification", value: "PROPERTY"} 2 : {name: "dBusClass", value: "CLAIMS"} length : 3This is what my table looks like
Any ideas on how to display my 3 values on the table along side the file size and name?
Thanks in Advance
thanks @hong-duc for the solution.