1

I am developing a Cordova application and using PouchDB as database, which, when connection is available, replicates all the information to CouchDB. I am successfully storing simple text and image. I have been trying to store also video and audio, without luck.

The way I store the data is:

    var emo = {
        _id: timestamp,
        user: uuid,
        location: curLatLng,
        _attachments:
            {
                "image.jpg":
                {
                    content_type:"image\/jpeg",
                    data: image
                },
                "video.mp4":
                {
                    content_type:"video\/mp4",
                    data: video
                }
        }
    };
    db.put(emo, function callback(err, result) {
        if (!err) {
            //console.log('Successfully posted a todo!');
        }
    }); 

I created the "video" more or less in the following way: Cordova - Capture video and retrieve base64 data

So, at the end its format is blob.

First of all I am not sure if storing audio/video in PouchDB is possible. If it is possible, are you able to spot what I am doing wrong? Should I follow a different approach?

Thanks a lot for your time!

Community
  • 1
  • 1
Eylül
  • 139
  • 1
  • 3
  • 13
  • Have you seen the documentation: http://pouchdb.com/guides/attachments.html? – Chris Snow Sep 11 '15 at 14:38
  • Yes I saw. I first tried to save the path, so the variable in callback function "mediaFiles[0].fullPath". Then I also tried to save as blob, using the function here http://stackoverflow.com/questions/26733070/cordova-capture-video-and-retrieve-base64-data. I followed the documention, but I think I am missing a detail or storing video is not possible, as it is not mentioned in the documentation. (just text and image are specifically described.) – Eylül Sep 11 '15 at 14:56

1 Answers1

4

PouchDB definitely supports storing Blobs; there is a guide to attachments that explains how.

Here's a little demo showing how to store a file. You can upload any file from your file system, and it will be stored in PouchDB. Hope that helps!

nlawson
  • 11,510
  • 4
  • 40
  • 50
  • Thank you so much. Your response was very helpful. At the end I am able to store in PouchDB. However I am facing another issue. Right now I am able to store in PouchDB, but replication to CouchDB never happens on my physical Android device. Strangely this works on my PC's browser and on emulator. This actually was working two days ago also on my Android device. Can you guess the reason? – Eylül Sep 14 '15 at 13:14
  • Probably your CouchDB is not accessible from anywhere except the computer you are running it on. Try setting the "bind address" to 0.0.0.0 instead of 127.0.0.1. Make sure you can access it from another computer (e.g. the web browser on the Android device). – nlawson Sep 14 '15 at 21:39