Phonegap数据库问题

编程入门 行业动态 更新时间:2024-10-25 02:28:04
本文介绍了Phonegap数据库问题 - 将图像存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用选项创建一个非常基本的库存应用程序,以在库存中包含项目照片。除了照片部分,我还有的所有工作...

I am trying to make a very basic inventory application with the option to include a photo of items in the inventory. I have everything working except the photo part...

我看过这个

phonegap.pbworks/iPhone%3A-Camera-API

我可以让相机工作,但似乎无法将图像添加到数据库中 -

and I can get the camera to work, but do not seem to be able to add the image to the database -

这里有一些代码

数据库定义/创建 - simage是照片应该去的地方

The database definitions/creation - simage is where the photo should go

db.transaction( function(transaction) { transaction.executeSql( 'CREATE TABLE IF NOT EXISTS entries (' + 'id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' + 'date DATE, sitem TEXT, snumber TEXT, ' + 'scategory TEXT, scost TEXT, simage BLOB);' ); } );

这是保存记录(拍照后)

Here is saving the record (after picture is taken)

function insertEntry() { var date = sessionStorage.currentDate; var snumber = $('#number').val(); var sitem = $('#item').val(); var scategory = $('#category').val(); var scost = $('#cost').val(); var simage = $('#image').val(); db.transaction( function(transaction) { transaction.executeSql( 'INSERT INTO entries (date, sitem, snumber, scategory, scost, simage) VALUES (?, ?, ?, ?, ?, ?);', [date, sitem, snumber, scategory, scost, simage], function(){ refreshEntries(); jQT.goBack(); }, errorHandler ); } ); }

有关我缺少什么的想法吗?

Any thoughts on what I am missing?

谢谢。

推荐答案

你必须通过toDataUrl函数将图像(val()不能工作)转换为Base64画布......

You have to convert the image (val() isn't going to work) to Base64 via the toDataUrl function of the Canvas...

请参阅Jesse MacFadyen关于这样做的文章这里。有一点小问题,如果图像服务器源与页面源不一样,那么这段代码将无法在Phonegap之外工作,因为在画布中没有原点 - 清除标志,但这在Phonegap中运行时不影响页面...

See Jesse MacFadyen article on doing this here. One little gotcha, if the image server source is not the same the page source this code is not going to work outside of Phonegap due to not having an origin-clean flag in the canvas, however this does not affect the page when running in Phonegap...

更多推荐

Phonegap数据库问题

本文发布于:2023-10-24 13:39:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Phonegap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!