Javascript 如何使用普通POST请求将文件发送到应用程序脚本?

Javascript 如何使用普通POST请求将文件发送到应用程序脚本?,javascript,node.js,post,google-apps-script,request,Javascript,Node.js,Post,Google Apps Script,Request,我正在做简单的文件上传到应用程序脚本,但我面临着一些麻烦上传数据作为文件。假设我有以下代码: function doPost(e) { console.log(e) } 我在node.js中做了一个简单的POST请求 let formData = { theFile: { value: fs.createReadStream('myawersome.file'), options: { filename: 'myawersome.file

我正在做简单的文件上传到应用程序脚本,但我面临着一些麻烦上传数据作为文件。假设我有以下代码:

function doPost(e) {
  console.log(e)
}
我在node.js中做了一个简单的POST请求

  let formData = {
    theFile: {
      value: fs.createReadStream('myawersome.file'),
      options: {
        filename: 'myawersome.file',
        contentType: 'some/mimetype'
      }
    }
  }
  let params = {
    url: 'my-script-url',
    followAllRedirects: true,
    formData: formData
  }
  request.post(params)
那么,问题是什么呢。我在
doPost
中的
e
参数中没有看到任何文件。这是我的console.log输出

{"queryString":"","parameter":{},"contextPath":"","parameters":{},"contentLength":9483}

我可以看到我在请求中有一些数据,但所有数据都是空的<代码>e.参数。文件和
e.文件
未定义的
。我的文件在哪里?

调用
createReadStream
只创建流,不读取文件

要读取文件,请尝试以下操作:

var rs = fs.createReadStream('myawersome.file');


rs.on("data", function (chunk) {

    var content = chunk.toString();


    var formData = {
        theFile: {
            value: content,
            options: {
                filename: 'myawersome.file',
                contentType: 'some/mimetype'
            }
        }
    }

    var params = {
        url: 'my-script-url',
        followAllRedirects: true,
        formData: formData
    }

    request.post(params)

});
rs.resume(); // this launches the read

谢谢你的解决方案。我并没有尝试这个,但我决定在帖子正文中以base64字符串的形式发送文件,并且它与应用程序脚本配合得很好