将数组发送到Firestore存储会引发读取字节长度的类型错误。

huangapple go评论84阅读模式
英文:

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(&#39;/uploaduserdata&#39;, function(req, res){
  UploadFile(req.body.file)

  res.sendStatus(200)
}

//different file
export function UploadFile(file){
  console.log(&quot;hello testing&quot;)
  const storageRef = sRef(fileStore, &quot;/working&quot;);
  console.log(file)
  // &#39;file&#39; comes from the Blob or File API
  uploadBytes(storageRef, file).then((snapshot) =&gt; {
    console.log(&#39;Uploaded a blob or file!&#39;);
  });
}

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 &#39;byteLength&#39;)
    at file:///C:/Users/uname/Desktop/ETRestAPI/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js:1223:38
    at Array.forEach (&lt;anonymous&gt;)
    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) =&gt; {
    console.log(&#39;Uploaded a blob or file!&#39;);
  });

Did not think it mattered but it really did matter, now the array uploads.

huangapple
  • 本文由 发表于 2023年1月8日 20:21:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75047703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定