英文:
Sending array to storage on firestore is causing reading bytelength typeError
问题
以下是您要翻译的代码部分:
app.post('/uploaduserdata', function(req, res){
UploadFile(req.body.file)
res.sendStatus(200)
}
//different file
export function UploadFile(file){
console.log("hello testing")
const storageRef = sRef(fileStore, "/working");
console.log(file)
// 'file' comes from the Blob or File API
uploadBytes(storageRef, file).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
}
这是从文件中获得的打印输出:
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
... 1124 more items
]
这是发生的错误信息:
TypeError: Cannot read properties of undefined (reading 'byteLength')
at file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1223:38
at Array.forEach (<anonymous>)
at FbsBlob.getBlob (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1222:25)
at multipartUpload (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1784:26)
at uploadBytes$1 (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:2915:25)
at uploadBytes (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:3416:12)
at UploadFile (file:///C:/Users/uname/Desktop/ETRestAPI/getmodule.js:94:3)
at file:///C:/Users/uname/Desktop/ETRestAPI/index.js:103:3
at Layer.handle [as handle_request] (C:\Users\uname\Desktop\ETRestAPI\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\uname\Desktop\ETRestAPI\node_modules\express\lib\router\route.js:144:13)
请注意,上述代码和错误信息是通过翻译后提供的,我没有对其进行实际测试或修改。
英文:
app.post('/uploaduserdata', function(req, res){
UploadFile(req.body.file)
res.sendStatus(200)
}
//different file
export function UploadFile(file){
console.log("hello testing")
const storageRef = sRef(fileStore, "/working");
console.log(file)
// 'file' comes from the Blob or File API
uploadBytes(storageRef, file).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
}
this is the printout i get from the file
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
... 1124 more items
]
So im getting an array and the upload file does work since i tried it with a local image before. But now im sending an array from my client software.
Ive tried to read the file as a array million ways. If there is another body im not reading and just getting the length of the array.
It says blob or fileapi but its the same code for sending an array too.
TypeError: Cannot read properties of undefined (reading 'byteLength')
at file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1223:38
at Array.forEach (<anonymous>)
at FbsBlob.getBlob (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1222:25)
at multipartUpload (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1784:26)
at uploadBytes$1 (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:2915:25)
at uploadBytes (file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:3416:12)
at UploadFile (file:///C:/Users/uname/Desktop/ETRestAPI/getmodule.js:94:3)
at file:///C:/Users/uname/Desktop/ETRestAPI/index.js:103:3
at Layer.handle [as handle_request] (C:\Users\uname\Desktop\ETRestAPI\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\uname\Desktop\ETRestAPI\node_modules\express\lib\router\route.js:144:13)
答案1
得分: 1
解决方法如下:
uploadBytes(storageRef, new Uint8Array(file)).then((snapshot) => {
console.log('上传了一个 Blob 或文件!');
});
没有考虑它很重要,但实际上很重要,现在数组已经上传。
英文:
solved it by
uploadBytes(storageRef, new Uint8Array(file)).then((snapshot) => {
console.log('Uploaded a blob or file!');
});
Did not think it mattered but it really did matter, now the array uploads.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论