Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

images(byte[]) storage problem

6 replies [Last post]
  • Login or register to post comments
Wed, 12/12/2012 - 10:18
lcrsantos
Offline
Joined: 12/12/2012
Groups: None

In the previous version(1.8) I made a wrapper for caching and some unit tests arround it. Today, I updated the couchbase server to 2.0 version and suddenly it is impossible to register byte[] data, even if converted to string.

So the deal is I want to cache images that will be consumed later on by several distributed applications. What is the best way to you advise to do this?

Top
  • Login or register to post comments
Thu, 12/13/2012 - 06:17
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

When you say it is impossible to register what is the exact behavior of your application? (Any error? log?)

How do you access the data from your application?

- Which CLient SDK?

- Have you upgrade your application to the latest SDK ?
http://www.couchbase.com/develop

Do not hesitate to post code snippet this is helpful for the community to help you sove the issue.

Tegards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Thu, 12/13/2012 - 07:49
lcrsantos
Offline
Joined: 12/12/2012
Groups: None

First of all thanks for your answer tgrall.

Now the the real deal. I'm using the .net client and I've updated it, along with the couchbase server update, to the latest version on nuget (1.2.0).

The behaviour I'm having is really weird as I only get a false as output when i try to store a byte[] in couchbase server. Apparently there is no error. The server just cannot store it. I've checked the logs and I haven't seen any errors related to that operation. In fact there is no record of any error occurred after this new version installation.

Well now about the code itself. I've developed a cross-cutting sdk to be deployed in my company's infrastructure to provide applications with caching behaviour. One of the constraints of this development is that we dont want to reengineer the code of the applications due to problems like these. Those applications often consume image files that are used by the applications as byte[]. In the previous version of the server everything worked well and now the images are not neither stored or consumed.

My client initialization:
public CouchbaseCacheProvider(string bucketName, string[] connectionStrings)
{
Uri url;
var config = new CouchbaseClientConfiguration();

foreach (var item in connectionStrings)
{
_parameters = item.ToDictionary();
url = new Uri(string.Format(this._connectionString, _parameters["Host"], _parameters["Port"]));
config.Urls.Add(url);
}
config.Bucket = this._bucketName;
config.BucketPassword = string.Empty;

this._couchCli = new CouchbaseClient(config);
}

My Store method wrapper:
public bool Put(string key, object value, TimeSpan ttl)
{
bool success = false;

if (ttl == TimeSpan.MaxValue)
success = this._couchCli.Store(StoreMode.Set, key, value);
else
success = this._couchCli.Store(StoreMode.Set, key, value, ttl);

return success;
}

UnitTest of byte[] that fails:
public void PutByteArr()
{
//string byteArr = Encoding.UTF8.GetString(_image);
bool success = cacheProvider.Put("byteArrkey", _image, _testTTL);

Assert.IsTrue(success);
}

In this case assert throw exception becaus the PUT method return false. I really cant understand the reason and have in fact tried to convert the byte[] to an encoded string but it still fails.

Hope you can help me with this issue and thanks for your time once again.

Top
  • Login or register to post comments
Thu, 12/13/2012 - 08:56
john
Offline
Joined: 01/05/2012
Groups: None

I just ran the following code with the client 1.2.0 and server 2.0:

var fs = new FileStream("Bitmap1.bmp", FileMode.Open);
var data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
 
var result = client.ExecuteStore(StoreMode.Set, "img", data);
Console.WriteLine("Result: " + result.Success);
 
if (result.Success) { 
    var img = client.ExecuteGet("img").Value;
    Console.WriteLine("Len of img: " + (img as byte[]).Length);
}

The output is:

Result: True
Len of img: 1270
Press any key to continue . . .

Are you able to store other items?

Top
  • Login or register to post comments
Thu, 12/13/2012 - 09:09
lcrsantos
Offline
Joined: 12/12/2012
Groups: None

Yes, Im able to store simple system data like strings, ints, etc and also complex structures like classes, even arrays of other types except byte.

I will try to excute that code and see whats going on and report somtehing later.

Top
  • Login or register to post comments
Fri, 12/14/2012 - 07:54
lcrsantos
Offline
Joined: 12/12/2012
Groups: None

hello again, still not working for me.. i get a false.

can u show me your code for client configuration?

Ps.: i didnt remove the old version of the couchbase server and then install the new one.. i upgraded from the previous version, so you think that might have something to do with this??

Top
  • Login or register to post comments
Fri, 12/14/2012 - 08:43
john
Offline
Joined: 01/05/2012
Groups: None

var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/"));
config.Bucket = "default";

var client = new CouchbaseClient(config);

These are just the defaults, so nothing special in the config.

The upgrade shouldn't be an issue - especially if you're adding new keys. Even if you had existing keys, they shouldn't be a problem. If you use ExecuteStore instead of Store, what is the StatusCode.Value that is returned?

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker