Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #1029740 // hjs_imgUploadBase64Encoder

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (2650L) is out of date.

1  
sS hjs_imgUploadBase64Encoder() {
2  
  ret hscript([[
3  
    var imgConverted = false;
4  
    
5  
    function submitWithImageConversion(form) {
6  
      console.log("imgConverted: " + imgConverted + ", form: " + form);
7  
      if (imgConverted) return true;
8  
      imgConverted = true;
9  
      var file = $('#imgUploader')[0].files[0];
10  
      if (file == null) return true;
11  
      var reader = new FileReader();
12  
13  
      // delay form submit until reader is done
14  
      reader.onloadend = function () {
15  
        var b64 = reader.result.replace(/^data:.+;base64,/, '');
16  
        $("#f_img_base64").val(b64);
17  
        console.log("Got base64 data: " + b64.length);
18  
        setTimeout(function() {
19  
          $(form).submit();
20  
        }, 1000);
21  
      };
22  
23  
      reader.readAsDataURL(file);
24  
      return false;
25  
    }
26  
  ]]);
27  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029740
Snippet name: hjs_imgUploadBase64Encoder
Eternal ID of this version: #1029740/6
Text MD5: c43fbc86ea72a38b5cdf2099c71a0eb6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-10 15:22:21
Source code size: 818 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 216 / 302
Version history: 5 change(s)
Referenced in: [show references]