1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-09 13:30:04 +00:00

fix(*): switch to file upload approach with large datasets and special characters

This commit is contained in:
Krishna Acondy
2020-07-11 11:27:45 +01:00
parent b614bafd03
commit 77d7e03de5
9 changed files with 216 additions and 193 deletions

View File

@@ -479,38 +479,37 @@ export default class SASjs {
formData.append(name, file, `${name}.csv`);
}
} else {
// param based approach
const sasjsTables = [];
let tableCounter = 0;
for (const tableName in data) {
if (isError) {
return;
}
tableCounter++;
sasjsTables.push(tableName);
const csv = convertToCSV(data[tableName]);
if (csv === "ERROR: LARGE STRING LENGTH") {
isError = true;
errorMsg =
"The max length of a string value in SASjs is 32765 characters.";
}
// if csv has length more then 16k, send in chunks
if (csv.length > 16000) {
const csvChunks = splitChunks(csv);
// append chunks to form data with same key
csvChunks.map((chunk) => {
formData.append(`sasjs${tableCounter}data`, chunk);
});
} else {
requestParams[`sasjs${tableCounter}data`] = csv;
}
}
requestParams["sasjs_tables"] = sasjsTables.join(" ");
}
// param based approach
const sasjsTables = [];
let tableCounter = 0;
for (const tableName in data) {
if (isError) {
return;
}
tableCounter++;
sasjsTables.push(tableName);
const csv = convertToCSV(data[tableName]);
if (csv === "ERROR: LARGE STRING LENGTH") {
isError = true;
errorMsg =
"The max length of a string value in SASjs is 32765 characters.";
}
// if csv has length more then 16k, send in chunks
if (csv.length > 16000) {
const csvChunks = splitChunks(csv);
// append chunks to form data with same key
csvChunks.map((chunk) => {
formData.append(`sasjs${tableCounter}data`, chunk);
});
} else {
requestParams[`sasjs${tableCounter}data`] = csv;
}
}
requestParams["sasjs_tables"] = sasjsTables.join(" ");
}
console.log("Request params", requestParams);
for (const key in requestParams) {
if (requestParams.hasOwnProperty(key)) {
formData.append(key, requestParams[key]);
@@ -526,9 +525,7 @@ export default class SASjs {
if (isError) {
reject({ MESSAGE: errorMsg });
}
const headers: any = {
"Content-Type": "application/x-www-form-urlencoded",
};
const headers: any = {};
if (this._csrfHeader && this._csrf) {
headers[this._csrfHeader] = this._csrf;
}
@@ -720,9 +717,9 @@ export default class SASjs {
private getRequestParams(): any {
const requestParams: any = {};
// if (this._csrf) {
// requestParams["_csrf"] = this._csrf;
// }
if (this._csrf) {
requestParams["_csrf"] = this._csrf;
}
if (this.sasjsConfig.debug) {
requestParams["_omittextlog"] = "false";