【问题标题】:Can I use pouchdb to store images我可以使用 pouchdb 来存储图像吗
【发布时间】:2021-04-18 21:43:35
【问题描述】:

我正在寻找一种在移动应用中处理离线/在线情况的简单方法。看起来 pouchdb 是一个与 cloudant 配对使用的有趣选项。但是用它来存储像图像这样的二进制数据是个好主意吗?还是存储大小或其他有限制?

【问题讨论】:

    标签: pouchdb cloudant


    【解决方案1】:

    PouchDB 支持文档的附件,就像 CouchDB 一样。因此,应该可以将本地文件附加到 PouchDB 数据库,然后将数据同步到远程 CouchDB/Cloudant 数据库。

    这是离线优先存储的绝佳解决方案;您将遇到的存储限制取决于所使用的浏览器。 See PouchDB's FAQ page for the list of browsers and storage limits.

    如果您担心数据库中附件过多或过大会导致性能问题,您可以采用混合方法并使用附件来初始保存附加对象,但使用脚本服务器端获取附件,复制到对象存储,然后修改文档以包含附件新主页的 URL。然后您可以删除附件本身以减少存储空间。

    【讨论】:

      【解决方案2】:

      存储图像或文件

      <input type="file">
      

      js

      var input = document.querySelector('input');
      input.addEventListener('change', function () {
        var file = input.files[0]; // file is a Blob
      
        db.put({
          _id: 'mydoc',
          _attachments: {
            filename: {
              type: file.type,
              data: file
            }
          }
        }).catch(function (err) {
          console.log(err);
        });
      });
      

      http://bl.ocks.org/ntwcklng/f57b03c15e91c25e2cb5

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-15
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        • 2011-09-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多