From 1f5b34d933b1d6487e72fb5cf00c66f7cd3c8fcf Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Fri, 5 Apr 2024 21:34:53 -0600 Subject: [PATCH 1/2] Fix two small bugs with the RestAPI Datasource First bug: Spring automatically transforms binary content to base64, therefore the logic in the RestApiExecutor was causing the data to be encoded twice, causing much confusion and frustration for several weeks actually. Second bug: the fileUtils#saveDataAsFile function was not actually setting the type correctly when attempting to convert the base64 data to a binary blob, thus the files would _always_ download as a 'dms' file and it would never actually be openable. This also caused a lot of confusion. Both of these bugs together made it impossible to tell why stuff was broken. Combined this means that anytime you were trying to download binary data you would never actually be able to open the file, as it would be only base64 data inside of it. --- client/packages/lowcoder/src/util/fileUtils.ts | 2 +- .../main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/packages/lowcoder/src/util/fileUtils.ts b/client/packages/lowcoder/src/util/fileUtils.ts index 647122596..7b98e21ff 100644 --- a/client/packages/lowcoder/src/util/fileUtils.ts +++ b/client/packages/lowcoder/src/util/fileUtils.ts @@ -48,7 +48,7 @@ export async function saveDataAsFile({ data, filename, fileType, dataType }: Sav if (dataType === "base64") { const blob = new Blob([Buffer.from(data, "base64")], { - type: mime + ";charset=utf-16", + type: mim + ";charset=utf-16", }); return saveAs(blob, filename, { autoBom: true }); } diff --git a/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java b/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java index 84d053e62..9f3eaf122 100644 --- a/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java +++ b/server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java @@ -426,7 +426,7 @@ private ResponseBodyData parseResponseDataInfo(byte[] body, MediaType contentTyp } if (isBinary(contentType)) { return ResponseBodyData.builder() - .body(Base64.getEncoder().encode(body)) + .body(body) .dataType(ResponseDataType.BINARY) .build(); } From 64293b9f8f7d659576ae4e0c45c432d5d1e044a7 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Sat, 6 Apr 2024 12:13:46 -0600 Subject: [PATCH 2/2] Fix docs explaining how to download xlsx --- .../write-javascript/built-in-javascript-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build-apps/write-javascript/built-in-javascript-functions.md b/docs/build-apps/write-javascript/built-in-javascript-functions.md index 0bbbb6db0..777f01f2e 100644 --- a/docs/build-apps/write-javascript/built-in-javascript-functions.md +++ b/docs/build-apps/write-javascript/built-in-javascript-functions.md @@ -81,7 +81,7 @@ utils.downloadFile(query1.data, "users-data.xlsx") // Example: Download the results of query1 as a XLXS file named users-data. utils.downloadFile(restApiQuery.data, "users-data", { - fileType: "pdf", + fileType: "xlsx", dataType: "base64", }) ```