blobContent null on couch base lite

Hi, I hope everyone is well.

I am using couchbase lite to store an object information. These objects have information like id, lat and long. And I also store a blob.

The problem is when I try to get it. When I save it it is not null de blobContent, it is a byte array and it is not empty the Content type I use is " application/octet-stream". But for some strange reason. When I get the blob, it comes the sha, length, etc but not the content.

Is there any reason for this to happen? Or that the Content-type is affecting?

Content-Type is purely informational and has no affect on the storage. I can’t think of a reason that Content should be null. Can you provide the code that you use to drive this situation?

This how I’m driving this situation.

In the constructor of my object, I declare the Blob variable like this, and it works. I verify that the content is not getting null:

 template = Blob("application/octet-stream", fRegistry.binaryTemplate)

Then I use this code to save the hole data and Blob object:

 val uTemplate = data["uuidTemplate"] as String
 val mutableDocument = MutableDocument("user::${uTemplate}", data)

 try {
    val database = databaseManager.templatesDatabase
    mutableDocument.setBlob("template", template)
    database?.save(mutableDocument)
 } catch (e: CouchbaseLiteException) {
    Log.e(e.message, e.stackTraceToString())
}

Later, in another part of my app, I need to retrieve this information and Blob object. I retrieve all information related to that, except the blobContent:

       val query = QueryBuilder        
            .select(
                SelectResult.expression(Meta.id),
                SelectResult.all()
             ) 
             .from(DataSource.database(database))
              
        val templates = mutableListOf<Template>()

        query.execute().use { rs ->
                    
          for(row in rs) {
              val docID = row.getString(0) ?: return@let

              val doc = database.getDocument(docID)
              val template = doc?.getBlob("template")

               val templateObject = row.getDictionary(1)?.toMap()?.toTemplate(template) ?: return@let

                templates.add(templateObject)
          }
        }

I’m not pretty sure where I made a mistake. I would be grateful for any guidance and/or correction.

I would like to add a ss where I could corroborate that the blob is being saved. This ss debug is after database?.save sentence.

UPDATE:

I already solved. I thougth that it was enough by using getBlob function but I noticed that it’s necessary to use content getter function to make available the access to blobContent.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.