我想使用cURL将文本文件的内容发送到Google Spread Sheet。
的test.txt
this is the message from local
在本地shell上
curl -F name=value -F data1=@test.txt "https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxx/exec"
在Google Spread Sheet中的Google Apps脚本
function doPost(e){
Logger.log(e);
}
然后日志
Fri Jul 12 08:34:28 PDT 2013 INFO: {queryString=null, parameter={name=value}, contextPath=, parameters={name=[value]}, contentLength=316}
我找不到我发送的参数“data1”。
那么如何才能收到我发送的文件的内容?
提前谢谢。
答案 0 :(得分:1)
我能够使用--data-url-encode代替-F
来发布数据命令
curl --data-urlencode name=value --data-urlencode data2@test.txt "https://script.google.com/macros/s/xxxxxxxxxxxxxx/exec" -L --insecure
输出
{"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}
应用脚本
function doPost(e) {
var xx = ContentService.createTextOutput(JSON.stringify(e)).setMimeType(ContentService.MimeType.TEXT);
return xx;
}