简体   繁体   English

Base64字符串压缩

[英]Base64 string Compression

I have got an ActiveX Control that gets an image from a fingerprint device as base64 string. 我有一个ActiveX控件,它从指纹设备获取图像作为base64字符串。 The Active works great and I could transfer the returned base64 string to the server to be converted to a binary data and then to be saved to a database. Active的效果很好,我可以将返回的base64字符串传输到服务器,以转换为二进制数据,然后保存到数据库。 I use ASP.NET as server side technology and JavaScript as client side technology. 我使用ASP.NET作为服务器端技术,并使用JavaScript作为客户端技术。 The problem is that the base64 string is tool large and it would take from 30 to 40 seconds for the string to be transferred to the server. 问题是base64字符串的工具很大,将字符串传输到服务器需要30到40秒。 My question is: Is there any way to compress this base64 string on client (Browser) and deflate it back on server. 我的问题是:有没有办法在客户端(浏览器)上压缩此base64字符串并将其放回服务器上。

If the base64 image is really a jpeg or some other compressed image format, I wouldn't expect you to be able to get much extra compression out of it in the first place. 如果base64图像确实是jpeg或其他压缩图像格式,则我不希望您能够从中获得更多的额外压缩。 You'd also need to work out a way of posting the binary compressed data afterwards in a portable way, which may not be terribly easy. 您还需要设计出一种随后以可移植方式发布二进制压缩数据的方法,这可能并不容易。 (You may be able to pretend it's a file or something like that.) (您可能可以假装它是文件或类似文件。)

Just how large is this image? 这个图像到底有多大? 30 seconds is a very long time... 30秒是很长的时间...

on my linux system, using the bzip2 utility (which uses burrows-wheeler transform and then compresses), I reduce a jpg encoded in Base64 from 259.6KB to 194.5KB. 在我的Linux系统上,使用bzip2实用程序(使用burrows-wheeler转换然后进行压缩),我将以Base64编码的jpg从259.6KB减少到194.5KB。

Using gzip (which uses an LZ algorithm of some variety), I reduce it to 194.4KB. 使用gzip(使用各种LZ算法),将其减少到194.4KB。

So, yes you can compress it. 因此,是的,您可以压缩它。 the question is why do you want to? 问题是为什么要这么做? It sounds as though your problems are really lying elsewhere. 听起来好像您的问题确实在其他地方。

Base64 is a format that is usually only used to get around technical limitaions of sending binary data. Base64是一种通常仅用于解决发送二进制数据的技术限制的格式。 For example, a base64 string could be used in a GET request, like "website.com/page?q=BASE64ENCODED". 例如,可以在GET请求中使用base64字符串,例如“ website.com/page?q=BASE64ENCODED”。

You have two options: 您有两种选择:

Figure out how to send/recieve binary data in a POST request, then send the data in a different form and convert it appropriately on the server. 弄清楚如何在POST请求中发送/接收二进制数据,然后以另一种形式发送数据并在服务器上适当地进行转换。 -OR- Since this is a fingerprint device, I assume you're using it as a password, so you actually don't have to send the raw fingerprint data every time. -或者-因为这是指纹设备,所以我假设您将其用作密码,因此实际上不必每次都发送原始指纹数据。 Just make an SHA-1 hash of it, and compare it to a stored hash on the server. 只需对其进行SHA-1哈希,然后将其与服务器上存储的哈希进行比较即可。 This is just as secure and will take a fraction of a second to upload. 这同样安全,将花费一秒钟的时间上传。

Hope I helped! 希望我能帮上忙!

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

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