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

26
LINES

< > BotCompany Repo | #1029888 // hjs_fileUploadBase64Encoder [hjs_imgUploadBase64Encoder with renamed ids]

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

Libraryless. Click here for Pure Java version (2654L/17K).

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

Author comment

Began life as a copy of #1029740

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1029888
Snippet name: hjs_fileUploadBase64Encoder [hjs_imgUploadBase64Encoder with renamed ids]
Eternal ID of this version: #1029888/1
Text MD5: e6155c4695b732ea813d4a3270f3bdb7
Transpilation MD5: 2da7317566e7622d56be3ecfec6c0fc1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-27 17:18:57
Source code size: 750 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 185 / 258
Referenced in: [show references]