-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadFile.ts
48 lines (40 loc) · 1.67 KB
/
uploadFile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as fs from "file-system";
import { Mediafilepicker, FilePickerOptions } from 'nativescript-mediafilepicker';
attachFile() {
let extensions = [];
if (!isAndroid) {
extensions = [kUTTypePDF, kUTTypeText]; // you can get more types from here: https://developer.apple.com/documentation/mobilecoreservices/uttype
} else {
extensions = ['jpg', 'jpeg', 'png'];
}
let options: FilePickerOptions = {
android: {
extensions: extensions,
maxNumberFiles: 1
},
ios: {
extensions: extensions,
multipleSelection: true
}
};
let mediafilepicker = new Mediafilepicker();
mediafilepicker.openFilePicker(options);
mediafilepicker.on("getFiles", function (res) {
this.attachedFile = res.object.get('results');
console.dir(this.attachedFile);
const filePath = this.attachedFile[0].file; // "/storage/emulated/0/Download/test.pdf";
const fileExist = File.exists(filePath);
const file = File.fromPath(filePath);
const fileReaded = file.readSync((err) => {
console.log(err);
});
const file64base = android.util.Base64.encodeToString(fileReaded, android.util.Base64.DEFAULT);
});
mediafilepicker.on("error", function (res) {
let msg = res.object.get('msg');
console.log(msg);
});
}
}
// ACCESS TO EMULATOR FILE EXPLORER:
// https://stackoverflow.com/questions/13006315/how-to-access-data-data-folder-in-android-device