pouchdb-react-native icon indicating copy to clipboard operation
pouchdb-react-native copied to clipboard

PouchDB Sync not pulling attachments from remote db

Open ghost opened this issue 7 years ago • 2 comments

I'm developing an App on Expo with PouchDB. Everything has been working great until today when I realized that attachments were syncing to the remote DB and not syncing back to the local DB. Everything else syncs great just not the attachments. The data string is left blank.

The way my app works - user takes a photo, the photo is saved to a local PouchDB and sync's with a remote DB. Then I add a thumnail version to the Doc.

The odd part is that when I use allDocs from my remote DB, it comes back with base64 data but the sync doesn't seem to populate the local copy.

So I can put the file on my remote server and save a copy locally, but when I use sync, it doesn't pull the attachment back.

Here is my sync code:

import React from 'react';
import { Text, View, TouchableOpacity, StyleSheet, Button } from 'react-native';
import PouchDB from 'pouchdb-react-native';

PouchDB.plugin(require('pouchdb-adapter-asyncstorage').default);

export default class SettingScreen extends React.Component {
	static navigationOptions = {
		title: 'Settings',
	};
	constructor(props) {
		super(props);
		this.state = {
		}
	}

	_handleForceDBSync = () => {
		PouchDB.sync('[http server with couchdb]','remotedb',{attachments:true})
		.on('change', function (change) {
		  console.log('[PhotoInspect DB] PouchDB: yo, something changed!')
		}).on('paused', function (info) {
		  console.log('[PhotoInspect DB] PouchDB: replication was paused, usually because of a lost connection')
		}).on('active', function (info) {
		  console.log('[PhotoInspect DB] PouchDB: replication is active')
		}).on('denied', function (info) {
		  console.log('[PhotoInspect DB] PouchDB: replication was denied')
		}).on('complete', function (info) {
		  console.log('[PhotoInspect DB] PouchDB: replication was completed')
		}).on('error', function (err) {
		  console.log('[PhotoInspect DB] PouchDB: ',err)
		});
	}

	_handleDeleteLocalDB = () => {
		const db = new PouchDB('photoinspect', {adapter: 'asyncstorage'});
		db.destroy('photoinspect').then((e)=>{alert('Database removed.')})
	}

	render() {
      return (
      	<View>
      		<Button title="Force Database Sync" onPress={()=>{this._handleForceDBSync()}} />
      		<Button title="Delete Local Database" onPress={()=>{this._handleDeleteLocalDB()}} />
      	</View>
      )
    }
}

ghost avatar Jan 20 '18 00:01 ghost

+1, experiencing the same issue

reinhardholl avatar Apr 06 '18 09:04 reinhardholl

see https://github.com/stockulus/pouchdb-react-native/issues/68

there is currently a workaround version by @jurassix With the new Blob support of react-native it would be much easier to implement, but I have no time to rework at the moment

stockulus avatar Apr 06 '18 14:04 stockulus