火基上载图片时出现错误错误:ENOENT:没有这样的文件或目录

我已使用这段代码在Firebase上上传图像。我正在前端的file字段中传递缓冲区。但是得到错误

Error: ENOENT: no such file or directory

代码

const uploadImageToStorage = (file) => {
  console.log({ file })
  return new Promise((resolve,reject) => {
    if (!file) {
      reject('No image file');
    }
    let newFileName = `${file.originalname}_${Date.now()}`;

    let fileUpload = bucket.file(newFileName);

    const blobStream = fileUpload.createWriteStream({
      metadata: {
        contentType: 'application/json'
      }
    });

    blobStream.on('error',(error) => {
      console.log({ error },'55555555555555555555555')
      reject('Something is wrong! Unable to upload at the moment.');
    });

    blobStream.on('finish',() => {
      // The public URL can be used to directly access the file via HTTP.
      const url = format(`https://storage.googleapis.com/${bucket.name}/${fileUpload.name}`);
      console.log({url})
      resolve(url);
    });

    blobStream.end(file.buffer);
  });
}

const handler = async (request,reply) => {
  console.log('Upload Image',request.file);
  console.log('Upload Image',request.payload);

  let file = request.payload;
  if (file) {
    uploadImageToStorage(file).then((success) => {
      res.status(200).send({
        status: 'success'
      });
    }).catch((error) => {
      console.error(error,'dddddddddddddddddddddddddddddd');
    });
  }
}
zjytianlang 回答:火基上载图片时出现错误错误:ENOENT:没有这样的文件或目录

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3158862.html

大家都在问