简体   繁体   English

Gzip在Parse中压缩PDF文件

[英]Gzip compress PDF files in Parse

Is there a way to compress (gzip) PDF files in Parse? 有没有一种方法可以在Parse中压缩(gzip)PDF文件? Also, is this a good idea - I checked by gzipping a text-based PDF file, and the file size reduced by around 30%. 另外,这是个好主意吗?我通过gzip压缩了基于文本的PDF文件进行了检查,文件大小减少了约30%。

Simplified code example -- 简化的代码示例-

<input type="file" id="pdfFileUpload">

var fileUploadControl = $("#pdfFileUpload")[0];
var file = fileUploadControl.files[0];
// Compress file here
var parseFile = new Parse.File(name, file);
// Or compress parseFile here

parseFile.save().then(function() {
  // The file has been saved to Parse.
}, function(error) {
  // The file either could not be read, or could not be saved to Parse.
});

Here In this case, can we compress the file object by using the gzip compression method? 在这种情况下,我们可以使用gzip压缩方法压缩文件对象吗? What is the best way to do it? 最好的方法是什么?

Moreover, what is the recommended way to improve latency when uploading and downloading PDF files (~5 MB)? 此外,在上载和下载PDF文件(〜5 MB)时,建议的改善延迟的方法是什么?

It appears that you want to do this is the browser. 看来您要执行此操作的是浏览器。 The best solution is to rely on a client's browser, if you can afford it, to compress the PDF file, upload to Parse, download the compressed file from Parse and uncompress on the other client's browser. 最好的解决方案是依靠客户端的浏览器(如果您负担得起的话)压缩PDF文件,上传到Parse,从Parse下载压缩的文件并在其他客户端的浏览器上解压缩。 You can use Javascript implementation of zlib like Pako to do this in browser. 您可以像Pako一样使用zlib的Javascript实现在浏览器中执行此操作。 It seems that Parse backend is not yet delivering static content like files via CDNs, so if you really have concerns over network latency and delivery while you scale, you might want to host your files somewhere other than Parse. 似乎Parse后端尚未通过CDN传递文件之类的静态内容,因此,如果在扩展时确实担心网络延迟和传递,则可能希望将文件托管在Parse之外的其他地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM