Saving files in Couchbase document

Hi,

I have a question about performance issues related to files saving into couchbase document.
Is it a good idea, or its better to save and manage those as standalone files with references in couchbase?

In case its a bad idea - why? In case its ok - whts the correct approach?

@arkadyb -

It depends what the file contents are. If it’s JSON, yes store in CB. Otherwise, it’s probably better to store references. It’s really a hard question to answer without more detail, though.

-Jeff

I was thinking about images (user avatars). I read somewhere on couchbase.com about an approach to save either base64 into existing document field or standalone files - one file per document.

@arkadyb -

Yeah, just convert the images to bytes and store with a key. For example:

var bytes = File.ReadAllBytes(@"C:\Users\...\Desktop\Pics\bob-ross-style.png");
using (var bucket = _cluster.OpenBucket())
{
    //store in the server
    var result = bucket.Upsert("bob-ross-style", bytes);
    if (result.Success)
    {
         result = bucket.Get<byte[]>("bob-ross-style");
         File.WriteAllBytes(@"C:\Users\..\Desktop\Pics\bob-ross-style2.png", result.Value);
    }
} 

I hope that helps!

-Jeff