[英]Send compressed PDF file contents from client side to backend server
I'm using ilovepdf to compress a pdf file uploaded at the client side.我正在使用ilovepdf压缩在客户端上传的 pdf 文件。 I get the compressed file contents as the response.我得到压缩文件内容作为响应。
Ideally what I want is to -:理想情况下,我想要的是-:
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.我还尝试将压缩文件内容附加到 DOM 元素并使用 formdata 提交到后端,但是,当我使用后端收到的内容保存文件时,我发现文件已损坏或无法打开。
Below code is triggered for download from ilovepdf server and upload to my server.下面的代码被触发从 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: 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.