Firebase Error: First argument has a key path longer than 768 Bytes

孤者浪人 提交于 2020-12-15 04:58:29

问题


I am trying to save an image of a canvas to my firebase database. But when I try to save it I get the following error.

Uncaught Error: Reference.set failed: First argument has a key path longer than 768 bytes (6829)

Is there any way I can make this string shorter so I could submit it. Below is the code I use to convert it to URL

function saveFunction(){

var canvas = document.getElementById("sheet");
var dataURL = canvas.toDataURL();
console.log(dataURL);
firebase.database().ref('Cords/' + dataURL).set({
      Canvas:dataURL
  });
}

回答1:


A common way to shorten the string and keep it reasonably unique is to use its hash. You could use a simple numeric hash, an MD5 hash or one of the many other hashes.

Just keep in mind that the shorter the hash, the bigger the chances are of two strings mapping to the same hash value. So you'll want to use a hash that is reasonably long, to prevent such collisions.



来源:https://stackoverflow.com/questions/65091996/firebase-error-first-argument-has-a-key-path-longer-than-768-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!