I'm using ilovepdf to compress a pdf file uploaded at the client side. I get the compressed file contents as the response.
Ideally what I want is to -:
- Make a file(PDF) at the client side with file contents received response.
- Attach the document to the file upload DOM element.
- Submit the file to the backend.
But it looks like reading/writing a file with contents at client side(browser) is forbidden. So above could not be acheived. I also tried attaching just compressed file contents to a DOM element and submitting to backend with formdata, however, when i save file with contents received at backend, I find the file as damaged or cannot open.
Below code is triggered for download from ilovepdf server and upload to my server.
function downloadPDF() {
  $.ajax({
    type: 'GET',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    url: "https://" + server + "/v1/download/" + task,
    success: function(response) {
      var form = new FormData();
      form.append("file", response);
      $.ajax({
        type: 'POST',
        url: "/properties/compressed",
        processData: false,
        contentType: false,
        data: form,
        success: function(response) {
          console.log("sent to server")
        }
      });
    }
  });
}

 
    