简体   繁体   English

如何使用cURL将文本文件发送到GAS?

[英]How can I send a text file to GAS , using cURL?

I want to send the content of the text file to Google Spread Sheet, using cURL. 我想使用cURL将文本文件的内容发送到Google Spread Sheet。

test.txt 的test.txt

this is the message from local

on the local shell 在本地外壳上

 curl -F name=value -F data1=@test.txt "https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxx/exec"

in the Google Apps Script in Google Spread Sheet 在Google Spread Sheet的Google Apps脚本中

function doPost(e){
   Logger.log(e);
}

then the log is 那么日志是

 Fri Jul 12 08:34:28 PDT 2013 INFO: {queryString=null, parameter={name=value}, contextPath=, parameters={name=[value]}, contentLength=316}

I can not find the parameter "data1" that I sent. 我找不到发送的参数“ data1”。

So how can I recieve the content of the file I sent?? 那么我如何才能收到我发送的文件的内容呢?

Thank you in advance. 先感谢您。

I was able to POST data using --data-url-encode instead of -F 我能够使用--data-url-encode而不是-F来发布数据

Command 命令

 curl --data-urlencode name=value --data-urlencode data2@test.txt "https://script.google.com/macros/s/xxxxxxxxxxxxxx/exec" -L --insecure

Output 产量

 {"queryString":null,"postData":{"contents":"name=value&data1=This%20is%20the%20content%20of%20my%20test.txt%20file","type":"application/x-www-form-urlencoded","name":"postData","length":70},"parameter":{"data1":"This is the content of my test.txt file","name":"value"},"contextPath":"","parameters":{"data1":["This is the content of my test.txt file"],"name":["value"]},"contentLength":70}

Apps Script 应用脚本

 function doPost(e) {

    var xx = ContentService.createTextOutput(JSON.stringify(e)).setMimeType(ContentService.MimeType.TEXT);
   return xx;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM