Skip to content

Commit b6ad6bd

Browse files
author
Ahmed Elsayed
committed
fix(mobile-resources-native): read the files unencrypted in download file jsaction
1 parent 500cda3 commit b6ad6bd

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
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: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import { Platform } from "react-native";
99
import RNBlobUtil from "react-native-blob-util";
1010
import FileViewer from "react-native-file-viewer";
11-
import mimeTypes from "mime";
12-
1311
// BEGIN EXTRA CODE
1412
function formatPath(...pathArgs: string[]): string {
1513
return pathArgs.filter(arg => !!arg).join("/");
@@ -51,24 +49,17 @@ export async function DownloadFile(file: mendix.lib.MxObject, openWithOS: boolea
5149

5250
const dirs = RNBlobUtil.fs.dirs;
5351
const fileName = file.get("Name") as string;
54-
const mimeType = mimeTypes.getType(fileName);
5552
const sanitizedFileName = sanitizeFileName(fileName);
5653
const baseDir = Platform.OS === "ios" ? dirs.DocumentDir : dirs.DownloadDir;
5754
const filePath = mx.data.getDocumentUrl(file.getGuid(), Number(file.get("changedDate")));
58-
let accessiblePath;
55+
const accessiblePath = await getUniqueFilePath(baseDir, sanitizedFileName);
56+
5957
if (Platform.OS === "ios") {
60-
accessiblePath = await getUniqueFilePath(baseDir, sanitizedFileName);
6158
await RNBlobUtil.fs.cp(filePath, accessiblePath);
6259
} else {
63-
accessiblePath = await RNBlobUtil.MediaCollection.copyToMediaStore(
64-
{
65-
name: sanitizedFileName,
66-
mimeType: mimeType ?? "*",
67-
parentFolder: ""
68-
},
69-
"Download",
70-
filePath
71-
);
60+
const base64Data = await mx.readFileBlob(filePath);
61+
const base64Content = base64Data?.split(",")[1];
62+
await RNBlobUtil.fs.createFile(accessiblePath, base64Content, "base64");
7263
}
7364
if (openWithOS) {
7465
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)