AppGyver with cordova Sqlite Plugin

424 views
Skip to first unread message

Derek Ekins

unread,
Mar 24, 2014, 5:18:11 PM3/24/14
to pou...@googlegroups.com
Hi,
I am creating an application using AppGyver.
My app stores images and videos as blob attachments. Initially I was not using the Sqlite plugin (not sure what that defaults to) and I could read and display my images no problem.
The videos are another story, however I thought I would try out the Sqlite plugin and see if that would help...

Now that I have enabled the SqlitePlugin my images no longer display at all (I assume there is an error somewhere but I can't find it). I am using the URL.createObjectURL method and if I inspect the img src attribute I can see it has a url, I can also log out the blob that is being fetched.

Any idea what I am doing wrong here?

Thanks,
Derek

Calvin Metcalf

unread,
Mar 24, 2014, 5:25:47 PM3/24/14
to pou...@googlegroups.com
so you are storing the blob in PouchDB and then fetching it and displaying it by creating a blob url?


--
You received this message because you are subscribed to the Google Groups "PouchDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pouchdb+u...@googlegroups.com.
To post to this group, send email to pou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pouchdb/b5d9b5ef-6c21-4540-abfa-46237d3bf902%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-Calvin W. Metcalf

Derek Ekins

unread,
Mar 24, 2014, 5:30:22 PM3/24/14
to pou...@googlegroups.com
yeah, well actually that is a good point.
I am storing an attachment in CouchDB and replicating to PouchDB.
This is how I am storing the attachment in couch (using nano in nodejs)

    request("http://...something.jpg").pipe(myDb.attachment.insert(asset._id, 'original', null, 'image/jpg'))

Once the data has replicated I am then creating a blob url.


Calvin Metcalf

unread,
Mar 24, 2014, 5:37:58 PM3/24/14
to pou...@googlegroups.com
so first question, can you view the images in couchdb?



For more options, visit https://groups.google.com/d/optout.



--
-Calvin W. Metcalf

Derek Ekins

unread,
Mar 24, 2014, 5:40:00 PM3/24/14
to pou...@googlegroups.com
Yes I can view the images in couch.
I can also view the images using my app when it runs in Chrome.


no...@nolanlawson.com

unread,
Mar 24, 2014, 7:35:49 PM3/24/14
to pou...@googlegroups.com
Another question: what platform are you using, and what version of PouchDB? Before PouchDB 2.0.0, image attachments in WebSQL (and hence the SQLite plugin) were not working.

FWIW in PouchDroid I have unit tests that confirm png images are storeable: https://github.com/nolanlawson/PouchDroid/blob/master/tests/unit/src/com/pouchdb/pouchdroid/test/AdvancedOperationsTest.java#L172 To be fair, PouchDroid uses a slight variation on the SQLite Plugin, but it ought to work the same. I'll check soon and see.

- Nolan

Derek Ekins

unread,
Mar 25, 2014, 4:13:47 AM3/25/14
to pou...@googlegroups.com
I am using PouchDB 2.0.1 and this is on iOS 7.1


no...@nolanlawson.com

unread,
Mar 26, 2014, 4:00:27 PM3/26/14
to pou...@googlegroups.com
Unfortunately these are the kinds of things that are really hard to debug in Cordova.  Some pointers that may help you out:

- Run this test at pouchtest.com on your device using Mobile Safari.  If any of the tests fail, send us the test report.


- Install the Cordova console.log plugin, so you can see errors in the console log

cordova plugin add org.apache.cordova.console

- Use weinre to get a console you can interact with:


FWIW we're working on getting our tests running in more environments (iOS, Android, with and without the sqlite plugin), but we're not there yet, so for now we're relying on users to give us bug reports. Thanks for your help!

Derek Ekins

unread,
Mar 28, 2014, 5:28:54 PM3/28/14
to pou...@googlegroups.com
Here are the results of my test run http://pouchtest.com/pouch-test-reports/index.html#testrun=testuser-691fd8e821aa6543e75f343ae13450a

I tried getting the document with attachments = true in the options.
The response in _attachments.myAttachment is:

  data"/9j/4A=="

Compare this to the same response from websql in chrome:

  data"/9j/4AAQSkZJRgABAQ...SNIP...UUUB//9k="

So there is something strange going on there by the looks of things.




no...@nolanlawson.com

unread,
Mar 31, 2014, 10:01:17 AM3/31/14
to pou...@googlegroups.com
Sorry about that; it looks like you ran into this bug: https://github.com/daleharvey/pouchdb/pull/1733

It will be fixed in PouchDB 2.1.0, which is going to be released shortly.  Or if you can't wait, here's a nightly: https://dl.dropboxusercontent.com/u/2588462/pouchdb/20140331/pouchdb-nightly.jshttps://dl.dropboxusercontent.com/u/2588462/pouchdb/20140331/pouchdb-nightly.min.js.

And if that still doesn't work, then please send us the PNG file itself (assuming you can).  We've been working really hard to improve attachment support in WebSQL, but it wouldn't surprise me if there were still some kinks to work out.  Thanks!

- Nolan

Derek Ekins

unread,
Mar 31, 2014, 10:33:23 AM3/31/14
to pou...@googlegroups.com
Unfortunately that doesn't seem to fix the problem.
I am going to spend some time debugging this later in the week.. unless someone else figures it out before then!


Derek Ekins

unread,
Apr 2, 2014, 1:56:30 PM4/2/14
to pou...@googlegroups.com
I've done a little more investigation into this.

When the saveAttachment function is called I am getting this exception:

> Exception: TypeError: Type error

It occurs on this line https://github.com/daleharvey/pouchdb/blob/master/lib/adapters/websql.js#L552 and is unhandled. Unfortunately I can't seem to get any more information out of it than that.

I will look into it some more, but thought I would throw this out there in case you have any ideas :-)

Derek Ekins

unread,
Apr 27, 2014, 6:20:01 PM4/27/14
to pou...@googlegroups.com
Hi I am still experiencing this problem (pouch 2.1.2).
I added some extra logging into the adapter/websql.js file when saving so that I could see what data it was receiving.
The data was exactly the same as the data that gets replicated to chrome so it looks like the websql driver is at least being given the correct data to insert.

I then added  "console.log(result.rows.item(0).body)" to the _getAttachement function.
This returns the data right after reading it and before pouchdb modifies it at all. The data that I received on iOS was a truncated version of the file:

"C3BFC398C3BFC3A0"

with the actual file being

"C3BFC398C3BFC3A000104A4649460001010100480048000..." (trimmed on purpose)

The cordova sqlite plugin has a pull request (https://github.com/brodysoft/Cordova-SQLitePlugin/pull/1) that says it implements blob support as base64 strings. I know there has been a bit of back and forth on using blob vs base64 but I was just wondering whether this might have something to do with why it behaves strangely?

Any help appreciated.

Regards,
Derek
Reply all
Reply to author
Forward
0 new messages