我最初正在编写一个在 Android 上运行的 PhoneGap 应用程序。
我编写它是为了从相机收集图像并将其存储在数据库中(使用 HTML5 数据库功能的 SQLite 数据库)。
因此有两种选择,将图像存储在数据库中,并将图像存储在SD卡上并通过文件名引用它们。
那么将它们存储在SD卡上,我怎样才能阻止别人删除它们呢?我不能对,我的意思是他们也可以删除 SD 卡。
将它们存储在数据库中,HTML5 规范建议数据库不应大于 5 MB,如果是,则会询问用户是否要增加大小。但对于 PhoneGap 应用程序来说,这也许并不是真正的问题?
I am writing a PhoneGap application to work on Android initially.
I am writing it to collect images from the camera and store them in the database (a SQLite database using the HTML5 functionality for databases).
So there are two options, store the images in the database, and store the images on the SD card and reference them by filename.
So storing them on the SD card, how can I stop someone deleting them? I can't right, I mean they could remove the SD card too.
Storing them in the database, the HTML5 spec suggests that databases shouldn't be bigger than 5 MB, and if they are then the user will be asked if they want to increase the size. But perhaps this is not really an issue for a PhoneGap app?
发布评论
评论(1)
我的建议是将图像作为文件存储在文件系统上。拍摄照片后,它将存储在 SD 卡上,但随后您可以使用 File API 将图像移动到 /data/data/{app package name}。该目录受到保护,用户不太可能删除该沙箱中的文件。它还具有额外的好处,当您的应用程序被卸载时,该目录会被清理。
这将帮助您解决拍照和返回 Base64 数据的一系列问题。在很多手机上,摄像头都非常好,以至于 base64 编码的字符串会导致内存不足错误,因此我告诉人们尽可能避免使用 DATA_URL 选项。另外,现在您在数据库中存储的数据少了很多,并且不会那么容易遇到大小限制。
My recommendation is to store the images as files on the file system. After you take the picture it will be on the SD Card but then you use the File API to move the images to /data/data/{app package name}. That directory is protected and the user is very unlikely to delete the files in that sandbox. It also has the added bonus that when your application is uninstalled that the directory is cleaned up.
This will get you around a host of issues with taking a picture and returning Base64 data. On a lot of phones the camera is so good that the base64 encoded string causes an out of memory error so I tell people to avoid the DATA_URL option whenever then can. Plus, now you store a lot less data in your DB and won't run into size limits quite so easily.