]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
ui: utils: add more generic loadTextFromFile upload helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Nov 2020 22:08:43 +0000 (23:08 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Nov 2020 22:10:03 +0000 (23:10 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/Utils.js

index b70592b4ba851244a6ac012e7a9cce25d4a1c39b..1ccf3c0fa8bbada6aefe96e2c4a082e5a7ff009f 100644 (file)
@@ -1351,6 +1351,20 @@ Ext.define('PVE.Utils', { utilities: {
        reader.readAsText(file);
     },
 
+    loadTextFromFile: function(file, callback, maxBytes) {
+       let maxSize = maxBytes || 8192;
+       if (file.size > maxSize) {
+           Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
+           return;
+       }
+       /*global
+         FileReader
+       */
+       let reader = new FileReader();
+       reader.onload = evt => callback(evt.target.result);
+       reader.readAsText(file);
+    },
+
     diskControllerMaxIDs: {
        ide: 4,
        sata: 6,