Attachments are not being synced up most often to the CB server while we use SetBlob method

We have implemented offline attachment functionality in our project. But locally it is working fine though the attachments are not being synced up to the CB server. Rarely it works but most of the time the attachments are not being synced to server. The code snippet is given below.
Are we missing anything in the code. Please guide
Note:- The other properties of the JSON document like FirstName, City, State etc get updated right away
When we invoke the attachment APIs in the sync gateway rather than SetBlob, upload attachment is working perfect

 public bool AttachFile(string type, string id, string fileName, string contentType, Stream fileStream)
        {
            var doc = database.GetDocument(id);
            if (doc == null)
            {
                throw new DcfrException(string.Format("{0} with id {1} is not found", type, id), DcfrExceptionType.NotFound);
            }
            var docType = doc["type"];
            if (docType != null && docType.ToString().ToUpper() == type.ToUpper())
            {
                var document = doc.ToMutable();
                var blob = new Blob(contentType, fileStream);
                var attachments = document.GetDictionary(AttachmentPropertyName);
                if (attachments == null)
                {
                    var obj = new MutableDictionaryObject();                    
                    obj.SetBlob(fileName, blob);
                    document.SetDictionary(AttachmentPropertyName, obj);
                }
                else
                {
                    var mutableAttachments = attachments.ToMutable();
                    mutableAttachments.SetBlob(fileName, blob);
                    document.SetDictionary(AttachmentPropertyName, mutableAttachments);
                }                
                database.Save(document);
                return true;
            }
            else
            {
                throw new DcfrException(string.Format("{0} with id {1} is not found", type, id), DcfrExceptionType.NotFound);
            }

        }

Are any warnings/errors being logged by either CBL or SG?