简体   繁体   English

我可以安全地将base64图像存储在本地存储中吗?

[英]Can I safely store base64 images in local storage?

I would like to save an image to reuse it on several pages. 我想保存一个图像以在多个页面上重复使用。 The simplest way for me would be to use local storage. 对我而言,最简单的方法是使用本地存储。

Now, I'm wondering if it is a safe option. 现在,我想知道这是否是一个安全的选择。 I'm not sure about the size of the generated image, so I'm afraid that it could sometimes exceed the limit of the local storage capacity. 我不确定生成的图像的大小,因此担心有时它可能会超出本地存储容量的限制。

If it can help, here are the characteristics of a typical image: 如果可以帮助,以下是典型图像的特征:

  • 980x653 PNG 980x653 PNG
  • When saved, it weighs ~400ko 保存后重约400ko
  • base64 is ~33k chars (but I guess it can easily double) base64是〜33k字符(但我想它可以轻松翻倍)

Checkout this question: 查看此问题:

How to store and retrieve image to localStorage? 如何存储和检索图像到localStorage?

It should provide you with more insight to what the best way to achieve this is. 它应该使您对实现此目标的最佳方法有更多的了解。 If you can guarentee that the image won't be greater than 5mb then go ahead! 如果您可以确保图片不会大于5mb,那就继续吧! You could always do some validation to check whether it's too large. 您始终可以进行一些验证以检查其是否太大。 You could also compress the image if it's too big and then save it, although quality will be lost. 如果图像太大,也可以将其压缩,然后保存,尽管会降低质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM