我試圖從third-party service的多個文檔創建一個UrlFetchApp()負載。如果我按照他們的示例對多個嵌入式文檔進行操作,則UrlFetchApp()有效內容應包含二進制文件(用於每個文件)和文本(用於分隔兩段內容)。如何將這個混合內容提供給有效載荷高級參數?帶有混合二進制和文本有效負載的Google Apps腳本UrlFetchApp()
我已經成功地完成二進制只使用.getBytes()上的斑點如下:
function testfax() {
var faxnum = '12125551234';
var url = 'https://rest.interfax.net/outbound/faxes?faxNumber=+'+faxnum;
Logger.log('url='+url)
Logger.log(" ")
var varAuthString = AuthString(); //user function to create HTTP simple authorization header
//Logger.log(varAuthString)
//Logger.log(" ")
var accept = "application/xml";
var meth = 'POST';
var payloadBlob = testDocBlob("For-Testing-Fax"); //user function returns GAS blob mime type "application/pdf"
var payload = [];
payload = payloadBlob.getBytes();
Logger.log(payload.length)
var contentType = "application/pdf"
var ContentLen = 0;
var headers =
{
"Accept": accept ,
"Authorization": "Basic " + varAuthString
}
//Logger.log("headers= ")
//Logger.log(headers)
//Logger.log(" ")
var options =
{
"method" : meth,
"headers" : headers,
"contentType":contentType,
"contentLength": ContentLen,
"payload" : payload
};
//Logger.log("options= ")
//Logger.log(options)
//Logger.log(" ")
var r = UrlFetchApp.fetch(url,options);
Logger.log(r.getResponseCode());
Logger.log(r.getContentText());
Logger.log(r.getHeaders());
}
這確實有助於拉它一起!我還在GAS文檔中發現了以下未解決的問題。任何與多部分和多類型問題鬥爭的人都可能想要爲它加註星標。 http://code.google.com/p/google-apps-script-issues/issues/detail?id=1387 –