-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSaveToPictureLibrary.ts
More file actions
43 lines (36 loc) · 1.47 KB
/
SaveToPictureLibrary.ts
File metadata and controls
43 lines (36 loc) · 1.47 KB
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
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { CameraRoll } from "@react-native-camera-roll/camera-roll";
// BEGIN EXTRA CODE
// END EXTRA CODE
/**
* @param {MxObject} picture - This field is required.
* @returns {Promise.<string>}
*/
export async function SaveToPictureLibrary(picture?: mendix.lib.MxObject): Promise<string> {
// BEGIN USER CODE
// Documentation https://facebook.github.io/react-native/docs/cameraroll#savetocameraroll
if (!picture) {
return Promise.reject(new Error("Input parameter 'Picture' is required"));
}
if (!picture.inheritsFrom("System.FileDocument")) {
const entity = picture.getEntity();
return Promise.reject(new Error(`Entity ${entity} does not inherit from 'System.FileDocument'`));
}
const guid = picture.getGuid();
const changedDate = picture.get("changedDate") as number;
const url = mx.data.getDocumentUrl(guid, changedDate);
// Save the file as a photo to the camera roll.
try {
const savedUri = await CameraRoll.saveAsset(url);
return Promise.resolve(savedUri.node.image.uri);
} catch (error) {
return Promise.reject(error);
}
// END USER CODE
}