将格式化的int保存到firestore以用于Javascript
我有一个函数,它应该返回这样的格式将格式化的int保存到firestore以用于Javascript,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,我有一个函数,它应该返回这样的格式2.3mb function formatSize(bytes) { var kb = 1024; var ndx = Math.floor(Math.log(bytes) / Math.log(kb)); //var fileSizeTypes = ["bytes", "kb", "mb", "gb", "tb", "pb", "eb", "zb", "yb"]; var size = (bytes / kb / kb).toFixed(2);
2.3mb
function formatSize(bytes) {
var kb = 1024;
var ndx = Math.floor(Math.log(bytes) / Math.log(kb));
//var fileSizeTypes = ["bytes", "kb", "mb", "gb", "tb", "pb", "eb", "zb", "yb"];
var size = (bytes / kb / kb).toFixed(2);
var sizeInString = size.toString() + 'mb';
return sizeInString;
} // This is just a sample script. Paste your real code (javascript or HTML) here.
if ('this_is' == /an_example/) {
of_beautifier();
} else {
var a = b ? (c % d) : e[f];
}
当我尝试将其放入firestore时,它返回一个错误
Uncaught (in promise) Error: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field size)
其余的是:
var fileSize = formatSize(fileN[0].size);
及
为什么firestore无法保存该字段。发现问题在于函数之间的参数传递错误,导致变量无法获取最上面的值
function putMessage(fileName, fileSize) {
db.collection("user").doc("document").collection('occur').add({
name: fileName,
size: fileSize,
})
.then(function(docRef) {
console.log("Document written");
})
.catch(function(error) {
console.error("Error putting Message:", error);
});
}