其中SQL数据类型来存储的Base64 EN codeD文件? [英] Which SQL data type to store Base64 encoded file?

查看:1174
本文介绍了其中SQL数据类型来存储的Base64 EN codeD文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为nvarchar(最大),VARCHAR(最大值),还是应该我真的去code字符串,并把它的图像或BLOB或什么?在

nvarchar(max), varchar(max), or should I really decode the string and put it in an image or blob or something?

我有一个.net SOAP的Web服务,它保存在一个SQL数据库2008年的记录。该服务将被扩展到接受的形象,这(或好或坏),也需要进入DB是暂时的。

I've got a .Net SOAP web service, which saves records in a SQL 2008 DB. The service is going to be extended to accept an image, which (for better or worse) also needs to go into the DB temporarily.

为了简单起见,该服务将图像作为基地64 CS codeD字符串,将不得不放弃回为Base64 EN codeD字符串后(在相同的服务不同的方法)

To keep things simple, the service takes the image as a Base 64 encoded string, and will have to give it back as a base64 encoded string later (a different method on the same service).

我本来只打算使用为nvarchar(max)和我敢肯定这会工作。但转念一想那的base64 EN codeD意味着它可以使用VARCHAR(最大值)来代替,并使用更少的存储空间。这是正确的吗?或者我应该硬着头皮去code文本二进制文件,其存储为一个blob,然后重新连接code它的出路又?

I was originally just going to use nvarchar(max), and I'm sure this would work. But then I thought that base64 encoded means it could use varchar(max) instead, and use less storage space. Is this right? Or should I bite the bullet and decode the text to binary, store it as a blob, and then re-encode it on the way out again?

最后 - 负载存储和性能不易引起问题,这是一个宠物项目和将低负荷

Finally - load storage and performance are unlikely to cause problems, this is a pet project and will be low load.

编辑:在回答@ howiecamp的问题,我写了我是如何在这里URL编码图像:<一href=\"http://www.flowerchild.org.uk/archive/2010/06/13/base-64-encoding-an-image-to-pass-across-a-web.html\">http://www.flowerchild.org.uk/archive/2010/06/13/base-64-encoding-an-image-to-pass-across-a-web.html

In response to @howiecamp's question, I wrote up how I was URL encoding the image here: http://www.flowerchild.org.uk/archive/2010/06/13/base-64-encoding-an-image-to-pass-across-a-web.html

推荐答案

好了,Base64是一个ASCII编码,真的 - 所以肯定不需要NVARCHAR - 并且由于它是文字,我建议 VARCHAR(MAX)

Well, Base64 is a ASCII encoding, really - so definitely no need for NVARCHAR - and since it's text, I'd suggest VARCHAR(MAX)

这是纯文本,高达2 GB(应该是足够了),这是一个字符串类型的,所以你可以使用它的所有字符串函数。每个字符总是2字节 - - NVARCHAR确实使用两倍的存储。并且完全没有必要在这种情况下

It's pure text, up to 2 GB (should be enough), and it's a string-type, so you can use all string functions on it. NVARCHAR does indeed use twice as much storage - always 2 bytes per character - and is totally unnecessary in this case.

这篇关于其中SQL数据类型来存储的Base64 EN codeD文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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