Skip to content

Commit f05c748

Browse files
[MOO-1317] Fix file download jsAction - read the files unencrypted (#117)
2 parents 500cda3 + 47c3348 commit f05c748

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/jsActions/mobile-resources-native/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- fixed an Android issue in Download file action.
12+
913
## [6.0.0] Native Mobile Resources - 2024-01-24
1014

1115
## BREAKING

packages/jsActions/mobile-resources-native/src/file-download/DownloadFile.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
88
import { Platform } from "react-native";
9-
import RNBlobUtil from "react-native-blob-util";
9+
import RNBlobUtil, { Mediatype } from "react-native-blob-util";
1010
import FileViewer from "react-native-file-viewer";
1111
import mimeTypes from "mime";
1212

@@ -51,24 +51,31 @@ export async function DownloadFile(file: mendix.lib.MxObject, openWithOS: boolea
5151

5252
const dirs = RNBlobUtil.fs.dirs;
5353
const fileName = file.get("Name") as string;
54-
const mimeType = mimeTypes.getType(fileName);
5554
const sanitizedFileName = sanitizeFileName(fileName);
5655
const baseDir = Platform.OS === "ios" ? dirs.DocumentDir : dirs.DownloadDir;
5756
const filePath = mx.data.getDocumentUrl(file.getGuid(), Number(file.get("changedDate")));
5857
let accessiblePath;
58+
5959
if (Platform.OS === "ios") {
6060
accessiblePath = await getUniqueFilePath(baseDir, sanitizedFileName);
6161
await RNBlobUtil.fs.cp(filePath, accessiblePath);
6262
} else {
63+
const tempPath = await getUniqueFilePath(baseDir, sanitizedFileName);
64+
const base64Data = await mx.readFileBlob(filePath);
65+
const base64Content = base64Data?.split(",")[1];
66+
await RNBlobUtil.fs.createFile(tempPath, base64Content, "base64");
67+
const mimeType = mimeTypes.getType(fileName) as Mediatype;
6368
accessiblePath = await RNBlobUtil.MediaCollection.copyToMediaStore(
6469
{
6570
name: sanitizedFileName,
6671
mimeType: mimeType ?? "*",
6772
parentFolder: ""
6873
},
6974
"Download",
70-
filePath
75+
tempPath
7176
);
77+
78+
RNBlobUtil.fs.unlink(tempPath);
7279
}
7380
if (openWithOS) {
7481
await FileViewer.open(accessiblePath, {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare namespace mx {
2+
interface MxInterface {
3+
readFileBlob: (filePath: string) => Promise<string>;
4+
}
5+
}

0 commit comments

Comments
 (0)