1

I am a hybrid mobile application developer. In my application, the user can enter their own HTML, CSS and javascript code and they can get its output. Now I have the plan create an HTML file from user typed code and send it through email or other sharing application. For sharing the HTML file I am using the following cordova plugin https://www.npmjs.com/package/cordova-plugin-email#determine-if-the-device-is-capable-to-send-emails

I can successfully generate and send the HTML file through mail, using the below code

cordova.plugins.email.open({
    to:      'merbi...@gmail.com',
    subject: 'Greetings',
    body:    '<h1>Test mail</h1> file generated from Test app',
    isHtml:  true,
    attachments:'base64:file.html//PGh0bWw+DQo8aGVhZD4NCjx0aXRsZT5UZXN0aW5nIHRpdGxlPC90aXRsZT4NCjwvaGVhZD4NCjxib2R5Pg0KVGhpcyBpcyB0aGUgdGVzdGluZyBib2R5DQo8L2JvZHk+DQo8L2h0bWw+'
});

But my problem is how to generate DATA URI from HTML strings? I can able to generate DATA URI from HTML file.

I used the following method to generate DATA URI Convert HTML to data:text/html link using JavaScript But it doesn't support.

Merbin Joe
  • 121
  • 13

1 Answers1

1

I don't know if you work with PHP. If you do you can use PHP like this:

$string = "I am a hybrid mobile application developer.";
$mime = "text/plain";
$base64 = base64_encode ( $string );
echo "data:$mime;base64,$base64";

If you don't work with PHP you may test the code in tehplayground and paste the output in a Firefox address bar to check the result.

I hope this helps.

enxaneta
  • 25,455
  • 4
  • 22
  • 32
  • I am not using an online application, it is the offline application, so I can not use any server-side code – Merbin Joe Aug 27 '18 at 15:13
  • If JavaScript is in your mind this may be helpful: [How can you encode a string to Base64 in JavaScript?]https://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript – enxaneta Aug 27 '18 at 16:59