-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJS_RevokeUploadedFileFromMemory.js
More file actions
50 lines (47 loc) · 2.7 KB
/
JS_RevokeUploadedFileFromMemory.js
File metadata and controls
50 lines (47 loc) · 2.7 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
44
45
46
47
48
49
50
// 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 "mx-global";
import { Big } from "big.js";
// BEGIN EXTRA CODE
// END EXTRA CODE
/**
* What does this JavaScript action do?
*
* After you have uploaded an image it removes locally stored image from memory. This is a custom build action.
*
* Dependency Note:
* This JavaScript action should be used only when you have inserted the Image Upload JavaScript Action called 'JS_UploadAndConvertToFileBlobURL' into your nanoflow.
*
* More detailed explanation: Memory management.
*
* To upload a image we use a custom build Javascript action called 'JS_UploadAndConvertToFileBlobURL'.
* Inside this action we use a JavaScript method called createObjectURL() to upload and store files in local memory. We can access and cosume this in memory image resource via the URL path that is returned from the createObjectURL() method.
*
* However, each time you call createObjectURL(), a new object is created in memory, even if you've already created one for the same object.
* So each of these must be released by calling this action called 'JS_RevokeUploadedFileFromMemory' when you no longer need them.
*
* Browsers will release object URLs automatically when the document is unloaded; however, for optimal performance and memory usage, if there are safe times when you can explicitly unload them, you should do so with the JavaScriptAction called 'JS_RevokeUploadedFileFromMemory'.
* @param {string} fileBlobURL - You have to pass the fileBlobURL that was created using the URL.createObjectURL() in the JS Action called 'JS_UploadAndConvertToFileBlobURL'
* @returns {Promise.<void>}
*/
export async function JS_RevokeUploadedFileFromMemory(fileBlobURL) {
// BEGIN USER CODE
/* We use the URL.createObjectURL() static method which creates a string containing a URL representing the
image uploaded.
The image blob is stored in the clients browser and takes up memory whilst the session is active. So here we
revoke the image when the user deletes the image. Note that the image is automaticlly revoked when the browser refreshes
or closes.
You have to pass the fileBlobURL that was created using the URL.createObjectURL() in the JS Action called 'JS_UploadAndConvertToFileBlobURL'
*/
if(fileBlobURL && typeof fileBlobURL === "string"){
URL.revokeObjectURL(fileBlobURL);
} else {
throw new Error("Image was not removed from browser memory");
}
// END USER CODE
}