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();
|
||||
|
||||
@@ -394,7 +394,7 @@ export let ae_api_data_struct: key_val = {
|
||||
|
||||
let ae_api_headers: key_val = {};
|
||||
ae_api_headers['Access-Control-Allow-Origin'] = '*';
|
||||
ae_api_headers['content-type'] = 'application/json';
|
||||
ae_api_headers['Content-Yype'] = 'application/json';
|
||||
ae_api_headers['x-aether-api-key'] = ae_api_data_struct.api_secret_key;
|
||||
ae_api_headers['x-aether-api-token'] = 'fake-temp-token';
|
||||
ae_api_headers['x-aether-api-expire-on'] = '';
|
||||
|
||||
@@ -306,7 +306,7 @@ async function get_url_cfg(cfg) {
|
||||
|
||||
// axios.defaults.baseURL = `${cfg.api_protocol}://${cfg.api_server}:${cfg.api_port}/${cfg.api_path}`;
|
||||
axios_api.defaults.headers.common['Access-Control-Allow-Origin'] = cfg.access_control_allow_origin; // '*'; // app_cfg.access_control_allow_origin;
|
||||
axios_api.defaults.headers.common['content-type'] = 'application/json';
|
||||
axios_api.defaults.headers.common['Content-Type'] = 'application/json';
|
||||
axios_api.defaults.headers.common['x-aether-api-key'] = cfg.api_secret_key;
|
||||
// axios_api.defaults.headers.common['x-account-id'] = cfg.account_id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user