How to add custom header (like Authentication) on upload request?
Thanks.
Fiel Upload
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Hi,
You can use onBeforeSend callback for it.
Or
customUpload and uploadHandler(files) to write the custom upload methods
Best Regards,
You can use onBeforeSend callback for it.
Code: Select all
const onBeforeSend = (xhr, formData) => {
xhr.setRequestHeader('Authorization', ...);
...
}
customUpload and uploadHandler(files) to write the custom upload methods
Best Regards,
Github Profile: https://github.com/mertsincan
-
- Posts: 3
- Joined: 02 Sep 2019, 15:02
Hi,
I tried inside onBeforeSend callback
but got error
I'm using PrimeReact version 6.4.1
I tried inside onBeforeSend callback
Code: Select all
const onBeforeUpload = (xhr, formData) => {
let token = '********_token_************';
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
Code: Select all
Uncaught TypeError: xhr.setRequestHeader is not a function
I'm using PrimeReact version 6.4.1
-
- Posts: 3
- Joined: 02 Sep 2019, 15:02
Hi,
also, when I debug, I saw that xhr object has xhr & formData object inside. When I changed function to
I got
best regards
also, when I debug, I saw that xhr object has xhr & formData object inside. When I changed function to
Code: Select all
const onBeforeUpload = (e) => {
let token = '********************_token_*****************';
e.xhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
Code: Select all
Uncaught DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Hi,
Please try;
Exp; https://codesandbox.io/s/happy-night-77 ... oadDemo.js
Best Regards,
Please try;
Code: Select all
const onBeforeSend = (e) => {
let token = '********************_token_*****************';
e.xhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
<FileUpload onBeforeSend={onBeforeSend} .../>
Best Regards,
Github Profile: https://github.com/mertsincan
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests