存储图像在文件系统中的BLOB [英] Storing image as a blob in filesystem

查看:198
本文介绍了存储图像在文件系统中的BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在存储数据库图像BLOB字段,但由于糟糕的表现和1MB光标的限制,我决定要切换到文件系统。我关心的几件事情。我在哪里专门存储图像?只需创建一个文件夹,并把它们里面呢?这是否与文件探险家对用户可见?我很担心,因为如果他们从用户删除我可能会失去参考这一切。

I have been storing images in database in a blob field, but because of bad performance and 1MB cursor limit, I decided to switch to file system. I am concerned about few things. Where do I specifically store the images? Just create a folder and put them inside ? Will that be visible to the user with file explorers? I am worried because I might lose reference to all these if they were to be deleted from the user.

推荐答案

您可以使用Android的缓存目录,它通常位于/ Android的/数据/ YOURPACKAGENAME /缓存

You can use Android's cache directory, it's generally located in /Android/data/YOURPACKAGENAME/cache

使用此code得到此路径。

Use this code to get this path.

最后弦乐cachePath =
  Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  ||
                          !isExternalStorageRemovable()? getExternalCacheDir(上下文).getPath():
                                  。context.getCacheDir()的getPath();

final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath();

显示位图高效检查由谷歌提供这个例子中,是,如果你的目标是从Web缓存图像非常有用。然而,它是用户可见和可容易地删除。

Displaying Bitmaps Efficiently check out this example provided by Google, it is very useful if your goal is to cache images from the web. However it is visible to the user and can be easily deleted.

如果你想隐藏的用户此文件,你可以简单地保存文件,而无需任何路径,这将是内部的数据/数据​​/ YOURPACKAGENAME,这是从用户隐藏,直到用户具有root访问权限。
示例

If you want to hide this files from user, you can simply save files without any path, it will be inside data/data/YOURPACKAGENAME, which is hidden from users until user has root access. Example

字符串文件名=hello_file;
串串=世界,你好!

String FILENAME = "hello_file"; String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

存储选项

这篇关于存储图像在文件系统中的BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆