[ACCEPTED]-Upload PDF as base64 file to the server using AJAX-base64

Accepted answer
Score: 10

I still really don't understand why you'd 1 want to do it this way, but if you must... FileReader Browser Support.


  <input type="file" name="file" id="resume">
  <input type="submit">


$('form').on('submit', function (e) {

    var reader = new FileReader(),
        file = $('#resume')[0];

    if (!file.files.length) {
        alert('no file uploaded');
        return false;

    reader.onload = function () {
        var data = reader.result,
            base64 = data.replace(/^[^,]*,/, ''),
            info = {
                name: "John",
                age: 30,
                resume: base64 //either leave this `basae64` or make it `data` if you want to leave the `data:application/pdf;base64,` at the start

            url: "http://example.com",
            type: "POST",
            dataType: "JSON",
            data: info,
            success: function (response) {}


More Related questions