保存到数据库之前先压缩文件 [英] compress file before saving into db

查看:55
本文介绍了保存到数据库之前先压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在维护一个应用程序,该应用程序将很多文档作为流存储在sql服务器中.

我有以下代码,例如

 字节 [] streamToUpload =   0 ,fileUpload1.PostedFile.ContentLength);
保存(idRequest,streamToUpload); 



save方法将文件保存在sql 2005表中.


我想知道是否有一种方法可以在保存之前先对流进行压缩,然后再使用一些免费的库将其解压缩
我要讨论的文件是.doc,.xls,.txt,.sql etcc,没有文件超过2 Mb

解决方案

可以使用内置的.NET命名空间System.IO.Compression.

在这里可以找到GZipStream类,该类可以压缩/解压缩流.

或者,如果您绝对要使用第三方软件,则可以尝试 ^

"

hi guys

i''m mantaining an application that have a lot of docs stored as stream in a sql server.

i have the following code for example

byte[] streamToUpload = new byte[fileUpload1.PostedFile.ContentLength];
fileUpload1.PostedFile.InputStream.Read(streamToUpload, 0, fileUpload1.PostedFile.ContentLength);
Save(idRequest, streamToUpload);



the save method saves the file in a sql 2005 table.


i''m wondering if there is a way to compress the stream before saving and uncompress before downloading it with some free library
the files i''m taling about are .doc, .xls, .txt, .sql etcc, no file is heavier than 2 Mb

any idea?

解决方案

You can use the built-in .NET namespace System.IO.Compression.

There you can find a GZipStream class that could allow you to compress/uncompress your streams.

Or, if you absolutely want to use a third-party software, you can try
SharpZipLib[^].


这篇关于保存到数据库之前先压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆