[英]Send compressed PDF file contents from client side to backend server
我正在使用ilovepdf压缩在客户端上传的 pdf 文件。 我得到压缩文件内容作为响应。
理想情况下,我想要的是-:
但看起来禁止在客户端(浏览器)读取/写入包含内容的文件。 所以以上无法实现。 我还尝试将压缩文件内容附加到 DOM 元素并使用 formdata 提交到后端,但是,当我使用后端收到的内容保存文件时,我发现文件已损坏或无法打开。
下面的代码被触发从 ilovepdf 服务器下载并上传到我的服务器。
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")
}
});
}
});
}
You can generate the PDF from your server by using wicked_pdf gem and encode the same in base64 return the base64 encoded string to client server and the on your client server you can use this code for download the PDF:
window.downloadPDF = function downloadPDF() {
var dlnk = document.getElementById('dwnldLnk');
dlnk.href = pdf; <this would be your return encoded string in response>
dlnk.click();
alert('toma');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.