{"action":"opened","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/982","repository_url":"https://api.github.com/repos/couchbase/couchbase-lite-android","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/982/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/982/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/982/events","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/982","id":173633892,"number":982,"title":"Replication error when edit/replace attachment of existing doc","user":{"login":"DanGDroid","id":10976856,"avatar_url":"https://avatars.githubusercontent.com/u/10976856?v=3","gravatar_id":"","url":"https://api.github.com/users/DanGDroid","html_url":"https://github.com/DanGDroid","followers_url":"https://api.github.com/users/DanGDroid/followers","following_url":"https://api.github.com/users/DanGDroid/following{/other_user}","gists_url":"https://api.github.com/users/DanGDroid/gists{/gist_id}","starred_url":"https://api.github.com/users/DanGDroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanGDroid/subscriptions","organizations_url":"https://api.github.com/users/DanGDroid/orgs","repos_url":"https://api.github.com/users/DanGDroid/repos","events_url":"https://api.github.com/users/DanGDroid/events{/privacy}","received_events_url":"https://api.github.com/users/DanGDroid/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-28T07:27:15Z","updated_at":"2016-08-28T07:27:15Z","closed_at":null,"body":"hi\r\ni create a doc with several attachments - audio and byte array - and replication is fine, i can see it on the server side - Syncgateway\r\nthe problem is when i edit the attachments of this doc on my local db it then has error on replication of these attachments\r\nsee log:\r\n\r\n08-25 09:22:43.567 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=3cc481a2-7f2f-4b00-b161-af81d5085db8, reason=Missing data of attachment \"sig2\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n08-25 09:22:43.567 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=47690d70-f8d2-44d1-aedf-e282d1333b88, reason=Missing data of attachment \"pageaudio2\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n08-25 09:22:43.568 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=3cc481a2-7f2f-4b00-b161-af81d5085db8, reason=Missing data of attachment \"sig3\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n08-25 09:22:43.568 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=47690d70-f8d2-44d1-aedf-e282d1333b88, reason=Missing data of attachment \"pageaudio3\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n08-25 09:22:43.568 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=47690d70-f8d2-44d1-aedf-e282d1333b88, reason=Missing data of attachment \"pageaudio3\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n08-25 09:22:43.568 2090-4721/com.sparkup.device W/Sync: {error=bad_request, id=47690d70-f8d2-44d1-aedf-e282d1333b88, reason=Missing data of attachment \"pageaudio3\", status=400}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@b7889e\r\n\r\ncouchbase 1.3\r\n\r\nwhen i add attachments it fails to replicate, but when i replace the last attachment on the audio list i replicates succefully the attachment and even faild attachments that i tryed to add before. ??\r\n\r\n\r\nthis is the code for replace/edit the document:\r\n\r\n`  private int SPK_UpdateBookInDB() {\r\n\r\n        String BookDocId = (String) currentbookmap.bookdescriptor.get(\"_id\");\r\n        String PagesDocId = (String) currentbookmap.pagedescriptor.get(\"_id\");\r\n        String AudioDocId = (String) currentbookmap.audiodescriptorlist.get(CurrentPlayVersion).get(\"_id\");\r\n        InputStream AudioFile = null;\r\n        ArrayList<Map<String, Object>> audioPlayTimeList = new ArrayList<>();\r\n        audioPlayTimeList = (ArrayList<Map<String, Object>>) currentbookmap.audiodescriptorlist.get(CurrentPlayVersion).get(KEY_AUDIO_PLAY_TIME_LIST);\r\n\r\n        int NumOfPages;\r\n        int BeforeUpdateNumOfPages =  (int) currentbookmap.bookdescriptor.get(KEY_NUMBER_OF_PAGES);\r\n        int BeforeUpdateNumOfPagesOfAudio = (int)currentbookmap.audiodescriptorlist.get(CurrentPlayVersion).get(KEY_NUMBER_OF_PAGES);\r\n        int UpdateNumberOfPageInAudio = 0;\r\n\r\n        //   audioPlayTimeList = (ArrayList<Map<String, Object>>) currentbookmap.audiodescriptorlist.get(CurrentPlayVersion).get(KEY_AUDIO_PLAY_TIME_LIST);\r\n        if (IsPageReplace) {\r\n            UpdateNumberOfPageInAudio = BeforeUpdateNumOfPagesOfAudio;\r\n         /*For existing page replace audio*/\r\n            NumOfPages = (int) currentbookmap.bookdescriptor.get(KEY_NUMBER_OF_PAGES);\r\n            int Duration;\r\n\r\n            Map<String, Object> pageAudioTime = new HashMap<String, Object>();\r\n            // Duration = currentbookmap.PageDescriptors[i].audioduration;\r\n            Duration = PageDescriptors[CurrentPageNumber].audioduration;\r\n            pageAudioTime.put(KEY_AUDIO_START_TIME, 0);\r\n            pageAudioTime.put(KEY_AUDIO_DURATION, Duration);\r\n            pageAudioTime.put(KEY_USER_GENERATED, true);\r\n            pageAudioTime.put(KEY_FILTER, false);\r\n            Log.d(TAG, \"SPK_UpdateBookInDB 1: duration \" + CurrentPageNumber + \" \" + Duration);\r\n\r\n            audioPlayTimeList.set(CurrentPageNumber, pageAudioTime);\r\n\r\n            try {\r\n                AudioFile = new FileInputStream(AUDIO_RECORD_FILE_PATH + PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber);\r\n            } catch (FileNotFoundException e) {\r\n                e.printStackTrace();\r\n                Log.e(TAG,\"SPK_UpdateBookInDB IsPageReplace FILE NOT FOUND\");\r\n                return -1;\r\n            }\r\n            Attachment AudioAttachment = db.getAttachment(AudioDocId, PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber);\r\n            if (AudioAttachment != null)\r\n                db.deleteAttachment(AudioDocId, PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber);\r\n\r\n            db.writeAttachment(AudioDocId, PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber, \"audio/audiofile\", AudioFile);\r\n            new File(AUDIO_RECORD_FILE_PATH + PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber).delete();\r\n\r\n            if (currentbookmap != null) {\r\n                /*Add audio to current json in cache*/\r\n                AudioAttachment = db.getAttachment(AudioDocId, PAGE_AUDIO_FILE_NAME_PREFIX + CurrentPageNumber);\r\n                if (AudioAttachment != null) {\r\n                    /*todo : crash if we add page which not exist*/\r\n                    currentbookmap.audiourlists.get(CurrentPlayVersion).put(CurrentPageNumber, AudioAttachment.getContentURL());\r\n                }\r\n            }\r\n        } else {\r\n\r\n             /*Book update for number of pages*/\r\n           /*Daniel say it does not matter because if we add pages...we not move back to play mode*/\r\n            //currentbookmap.bookdescriptor.put(KEY_NUMBER_OF_PAGES, new Integer(CurrentRecordingPageNumber + 1));\r\n            //NumOfPages = (int) currentbookmap.bookdescriptor.get(KEY_NUMBER_OF_PAGES);\r\n            NumOfPages = CurrentRecordingPageNumber + 1;\r\n\r\n            int Duration = -1;\r\n            int i;\r\n\r\n            for (i = 0; i < NumOfPages; i++) {\r\n                Map<String, Object> pageAudioTime = new HashMap<>();\r\n                if (i >= CurrentPageNumber + 1) {\r\n                    Duration = PageDescriptors[i].audioduration;\r\n                    pageAudioTime.put(KEY_AUDIO_START_TIME, 0);\r\n                    pageAudioTime.put(KEY_AUDIO_DURATION, Duration);\r\n                    pageAudioTime.put(KEY_USER_GENERATED, true);\r\n                    pageAudioTime.put(KEY_FILTER, false);\r\n                    Log.d(TAG, \"SPK_UpdateBookInDB 2: duration \" + i + \" \" + Duration);\r\n                    audioPlayTimeList.add(pageAudioTime);\r\n\r\n                }\r\n            }\r\n\r\n            //audioPlayTimeList.set(0,audioPlayTimeList.get(0));\r\n\r\n\r\n            if(CurrentPageNumber + 1 == NumOfPages) {\r\n                Log.e(TAG, \"SPK_UpdateBookInDB: no pages added\");\r\n                return -1;\r\n            }\r\n\r\n            for (i = CurrentPageNumber + 1; i < NumOfPages; i++) {\r\n\r\n                db.writeAttachment(PagesDocId, \"sig\" + i, \"bin/sigfile\", new ByteArrayInputStream(PageDescriptors[i].signature));\r\n\r\n                if (RecordingMethod != CONTINUES_RECORDING) {\r\n                    try {\r\n                        AudioFile = new FileInputStream(AUDIO_RECORD_FILE_PATH + PAGE_AUDIO_FILE_NAME_PREFIX + i);\r\n                        //AudioFile = new FileInputStream(Uri.parse(\"android.resource://com.sparkup.device/raw/prompt77heb\"));\r\n\r\n                    } catch (FileNotFoundException e) {\r\n                        e.printStackTrace();\r\n                        Log.e(TAG,\"SPK_UpdateBookInDB pageAdded FILE NOT FOUND\");\r\n                        return -1;\r\n                    }\r\n                    Log.e(TAG,\"SPK_UpdateBookInDB pageAdded AudioDocId \"+AudioDocId);\r\n\r\n                    db.writeAttachment(AudioDocId, PAGE_AUDIO_FILE_NAME_PREFIX + i, \"audio/audiofile\", AudioFile);\r\n\r\n                    new File(AUDIO_RECORD_FILE_PATH + PAGE_AUDIO_FILE_NAME_PREFIX + i).delete();\r\n                }\r\n            }\r\n            UpdateNumberOfPageInAudio = NumOfPages;\r\n        }\r\n        db.update(KEY_AUDIO_PLAY_TIME_LIST, audioPlayTimeList, AudioDocId);\r\n\r\n       db.update(KEY_NUMBER_OF_PAGES, UpdateNumberOfPageInAudio, AudioDocId);\r\n\r\n        if (NumOfPages > BeforeUpdateNumOfPages ) {\r\n\r\n            Log.e(TAG,\"SPK_UpdateBookInDB pageAdded 1 \"+BookDocId+\":\"+AudioDocId);\r\n            db.update(KEY_NUMBER_OF_PAGES, NumOfPages, BookDocId );\r\n        }\r\n        else\r\n        {\r\n            Log.e(TAG,\"SPK_UpdateBookInDB pageAdded 2 \"+BookDocId+\":\"+AudioDocId);\r\n\r\n            db.update(KEY_NUMBER_OF_PAGES, BeforeUpdateNumOfPages, BookDocId);\r\n        }\r\n        return 0;\r\n    }`\r\n\r\nplease advise."}}
{"actor":{"display_login":"DanGDroid"}}