gpt4 book ai didi

javascript - 将格式化的 int 保存到 Javascript 的 firestore

转载 作者:行者123 更新时间:2023-11-30 19:49:20 25 4
gpt4 key购买 nike

我有这个函数应该返回这样的格式 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);

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);
});
}

为什么 firestore 未能挽救这个领域。

最佳答案

发现问题是函数之间的参数传递错误导致变量无法获取值

关于javascript - 将格式化的 int 保存到 Javascript 的 firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54629855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com