title: Which SQL data type to store Base64 encoded file?
body: <p>nvarchar(max), varchar(max), or should I really decode the string and put it in an image or blob or something?</p>
  
  <h3>The longer version : (with all the juicy details)</h3>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>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?</p>
  
  <p>Finally - load storage and performance are unlikely to cause problems, this is a pet project and will be low load.</p>
  
  <p>Edit: In response to @howiecamp's question, I wrote up how I was URL encoding the image here: <a href="http://www.flowerchild.org.uk/archive/2010/06/13/base-64-encoding-an-image-to-pass-across-a-web.html" rel="noreferrer">http://www.flowerchild.org.uk/archive/2010/06/13/base-64-encoding-an-image-to-pass-across-a-web.html</a></p>