This is a migrated thread and some comments may be shown as answers.

Kendo Upload - how to set the content-type to post

3 Answers 1253 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 13 Feb 2018, 09:42 AM

Hi,

I'm trying to use the Upload control with a an asp.net core web api backend.

My server code is expecting to receive a file with a content-type of 'multipart/form-data', the Upload control is sending it as 'application/json'. Is there a way I can set the content-type of the posted file?

I tried setting the content-type in the UploadEvent (https://www.telerik.com/kendo-angular-ui/components/upload/api/UploadEvent/) 

 

uploadEventHandler(e: UploadEvent) {
    e.headers.set('Content-Type', 'multipart/form-data')
 }

but it was ignored.

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 13 Feb 2018, 12:13 PM
Hi Simon,

When uploading a file, the Upload component sends an HttpRequest of type FormData and the content type of the request is automatically set to 'multipart/form-data'. It is not needed to manually set it as part of the request headers.

Regards,
Dimiter Madjarov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Ramesh
Top achievements
Rank 1
commented on 04 Nov 2022, 04:05 PM

Hello Dimiter Madjarov,

       I want to set content type as this 
'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'

beforeSend={(xhr) => {xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' )}}
saveHeaders={{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }}


I tried in bot the ways, but no luck.
0
Simon
Top achievements
Rank 1
answered on 19 Mar 2018, 10:08 AM
Thanks. It was my mistake. I had an interceptor stepping in and setting the content-type to 'application/json' on all http actions. Oops!
0
Dimiter Madjarov
Telerik team
answered on 19 Mar 2018, 12:38 PM
Hi Simon,

Thank you for the update.

Have a great day!

Regards,
Dimiter Madjarov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Simon
Top achievements
Rank 1
Share this question
or