JavaScript add file to generate data through $ _POST

In the following usage example that I am trying to execute, only step 3 is not working yet, and I am working in Joomla 3.4 environment when I am working on the module here.

  • I have an html form requesting input and file upload.
  • I process this file using JavaScript for pgp to encrypt it (using this: https://keybase.io/kbpgp )
  • Now I want to replace the original file in the form with encrypted, or at least add encrypted to the form data. This is not working yet , how can I do this?
  • When everything is done in the JavaScript part form.submit();, it’s called
  • An email is sent with plaintext forms encrypted as body text, and the file should be added to the encrypted attachment.

Some information:

Sending the file in unencrypted form works very well, so I thought I could just add the encrypted one, but apparently it does not work. The form submits the original content and nothing contains the added file. I was already looking for some solutions, and this piece of code was the result of my research:

var data = new FormData();
data.append('upload_file' , result_buffer);
var xhr = new XMLHttpRequest();
xhr.open( 'POST', '', true );
xhr.setRequestHeader('Content-Type', 'multipart/form-data'); 
xhr.send(data);

var form = document.getElementById('formencryptmessage');
form.submit();

upload_file- this is the input of the form of the original unencrypted file; the $ _POST request saves the source file no matter what I do; result_buffer- binary buffer with file contents; finally, formencryptmessageis the form identifier and name.

Edit

The git repo with code is here: https://github.com/JamborJan/joomlaencryptedcontact

: https://github.com/JamborJan/joomlaencryptedcontact/blob/master/tmpl/default.php

, // . .

+4
1

, , pgp, base64, = hidden, DOM JavaScript.

script, , , base64. .

- Javascript, , , .

- > , Mave, , - , ? , , , , ​​( , , , , ).

, Base64 JavaScript, : - btoa() base64, - atob(), .

+1

All Articles