images(byte[]) storage problem
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?
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.
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?
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.
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??
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?
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