Important bug fix for posting form data. The headers are case sensitive. Changed them all to Content-Type.
This commit is contained in:
@@ -54,15 +54,21 @@ export let post_object = async function post_object(
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('HERE!! API POST 0');
|
||||
|
||||
if (!api_cfg) {
|
||||
console.error('No API Config was provided. Returning false.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// console.log('HERE!! API POST 1');
|
||||
|
||||
// Construct the URL with query parameters
|
||||
const url = new URL(endpoint, api_cfg['base_url']);
|
||||
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
|
||||
|
||||
// console.log('HERE!! API POST 2');
|
||||
|
||||
// Clean the headers
|
||||
let headers_cleaned: Record<string, string> = {};
|
||||
for (const prop in api_cfg['headers']) {
|
||||
@@ -70,8 +76,14 @@ export let post_object = async function post_object(
|
||||
headers_cleaned[prop_cleaned] = api_cfg['headers'][prop];
|
||||
}
|
||||
|
||||
// console.log('HERE!! API POST 3');
|
||||
|
||||
if (form_data) {
|
||||
headers_cleaned['Content-Type'] = 'multipart/form-data';
|
||||
// headers_cleaned['Content-Type'] = 'multipart/form-data';
|
||||
delete headers_cleaned['Content-Type'];
|
||||
delete headers_cleaned['content-type']; // Just in case
|
||||
delete headers_cleaned['Content-type']; // Just in case
|
||||
console.log('Form Data:', form_data);
|
||||
} else {
|
||||
headers_cleaned['Content-Type'] = 'application/json';
|
||||
}
|
||||
@@ -80,6 +92,8 @@ export let post_object = async function post_object(
|
||||
console.log('Cleaned Headers:', headers_cleaned);
|
||||
}
|
||||
|
||||
// console.log('HERE!! API POST 4');
|
||||
|
||||
for (let attempt = 1; attempt <= retry_count; attempt++) {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user