强大的firebase函数未定义文件对象

问题描述 投票:0回答:1
 exports.storePostData = functions.https.onRequest(function (request, 
response) {
cors(request, response, function () {
var uuid = UUID();
var formData = new formidable.IncomingForm();

formData.parse(request, function(err, fields, files) {

  fs.rename(files.file.path, '/tmp/' + files.file.name);
  var bucket = gcs.bucket('pwagram-87530.appspot.com');

  bucket.upload('/tmp/' + files.file.name, {
    uploadType: 'media',
    metadata: {
      metadata: {
        contentType: files.file.type,
        firebaseStorageDownloadTokens: uuid
      }
    }
  }, function(err, file) {

    if (!err) {
      admin.database().ref('posts').push({
        id: fields.id,
        title: fields.title,
        location: fields.location,
        rawLocation: {
          lat: fields.rawLocationLat,
          lng: fields.rawLocationLng
        },
        image: 'https://firebasestorage.googleapis.com/v0/b/' + bucket.name 
        + '/o/' + encodeURIComponent(file.name) + '?alt=media&token=' + uuid
      })

函数日志抛出错误“无法读取属性路径 未定义”,我猜这是因为强大的文件对象 是空的..如果有人可以提供帮助,我将不胜感激。我似乎无法弄清楚我做错了什么。

firebase google-cloud-functions formidable
1个回答
0
投票

您的表单 html 中有 enctype 属性吗?

<form action="run" method="post" enctype="multipart/form-data">

© www.soinside.com 2019 - 2024. All rights reserved.