将图像中的数据存储在 cookie 中
Store data from image in a cookie
我正在尝试将图像存储在 cookie 中,但我不知道这是否是防止用户在刷新页面时注册的最佳方式。
好吧,我正在使用 ngCookies 模块来做到这一点。所以我从服务器收到了一张 base64 字符串格式的图像、contentType 和数据,然后我存储在 cookie 中:
$cookies.contentType = value.image.contentType;
$cookies.data = value.image.data;
为了让我的 url 我这样做:
vm.url = "data:"+vm.value.image.contentType+";base64,"+vm.value.image.data;
我在页面中插入的 url 使用 img html:
<img src={{ctrl.url}} style="width:200px;height:200px">
我的问题是:当我刷新页面时,$cookies.contentType 仍然存在,但 value.data 不再存储在 $cookies.data 中。我认为这个值太大,无法存储在 cookie 中。我是否正确使用 cookie?还有其他方法吗?
如果有人能帮助我,我将不胜感激。
通常认为使用 cookie 进行客户端存储 less than ideal. Cookies are automatically sent back with every request (if it matches domain/path/security restrictions). Even if the cookie storage limit could handle this I can't imagine you would want to send this back with any future request. LocalStorage and similar technologies 部分是为了避免此问题而开发的。
也就是说,http cookie spec originally stated that a cookie needed to accommodate at least 4096 bytes which was then generally interpreted as setting a max size of approximately 4k. Each browser handles this a bit differently and there are plenty of places to read up on it。
我正在尝试将图像存储在 cookie 中,但我不知道这是否是防止用户在刷新页面时注册的最佳方式。
好吧,我正在使用 ngCookies 模块来做到这一点。所以我从服务器收到了一张 base64 字符串格式的图像、contentType 和数据,然后我存储在 cookie 中:
$cookies.contentType = value.image.contentType;
$cookies.data = value.image.data;
为了让我的 url 我这样做:
vm.url = "data:"+vm.value.image.contentType+";base64,"+vm.value.image.data;
我在页面中插入的 url 使用 img html:
<img src={{ctrl.url}} style="width:200px;height:200px">
我的问题是:当我刷新页面时,$cookies.contentType 仍然存在,但 value.data 不再存储在 $cookies.data 中。我认为这个值太大,无法存储在 cookie 中。我是否正确使用 cookie?还有其他方法吗?
如果有人能帮助我,我将不胜感激。
通常认为使用 cookie 进行客户端存储 less than ideal. Cookies are automatically sent back with every request (if it matches domain/path/security restrictions). Even if the cookie storage limit could handle this I can't imagine you would want to send this back with any future request. LocalStorage and similar technologies 部分是为了避免此问题而开发的。
也就是说,http cookie spec originally stated that a cookie needed to accommodate at least 4096 bytes which was then generally interpreted as setting a max size of approximately 4k. Each browser handles this a bit differently and there are plenty of places to read up on it。