Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:30:20+00:00 2026-06-18T04:30:20+00:00

I am trying to create a UrlFetchApp() payload from multiple documents for a third-party

  • 0

I am trying to create a UrlFetchApp() payload from multiple documents for a third-party service. If I follow their example for multiple inline documents, the UrlFetchApp() payload should contain both binary (for each file) and text (to separate the two pieces of content). How to I supply this mixed content to the payload advanced argument?

I have successfully done binary only using .getBytes() on a blob as follows:

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());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:30:21+00:00Added an answer on June 18, 2026 at 4:30 am

    You’ve got most of the code you need already, you just need to re-arrange it a bit and build in the multi-part handling.

    I suggest you modify your fax sending function to deal with an array of file blobs.
    Here’s what the code of your test function would look like, building up the array and calling your testfax() function:

    function testtestfax() {
      // Build an array with files for faxing.
      var files = [];
      // Repeat push line for multiple files.
      files.push(testDocBlob("For-Testing-Fax"));   //user function returns GAS blob mime type "application/pdf"
      testfax(files);
    }
    

    This way, you can set contentType depending on the length of the file array. If it’s a single file, take contentType=fileBlob.getContentType(), otherwise contentType=multipart/mixed... with an appropriate boundary parameter.

      if (files.length == 1) {
        var contentType = "application/pdf"
      }
      else {
        var boundary="265001916915724"
        var contentType = 'multipart/mixed; boundary="'+boundary+'"';
      }
    

    You can choose to use a hard-coded boundary like this – it’s interesting how often the one in this example shows up in searches. Better if you can generate your own random string. This is all described in Section 5.1 of RFC2046, Multipurpose Internet Mail Extensions.

    Once your contentType is set, build the payload of your message. If it’s a single file, payload consists only of files[0].getBytes(). Otherwise, loop through files, appending to payload for each one.

    The multipart payload for each file will consist of:

    • a blank line (CRLF), followed by..
    • the boundary string prepended by double-hyphens, followed by…
    • the content-type tag for the file. files[i].getContentType(), followed by…
    • files[i].getBytes()

    The multipart payload is then finalized by:

    • a blank line (CRLF), followed by…
    • the boundary string enclosed front and back with double-hyphens, signifying the end.

    The last part of your existing function remains as-is, setting up the options with the payload that has been constructed above, and using fetch() to send it off. You should now have a function that can handle single or multiple faxes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying create grammar for SRT format: Here is an example of srt file:
I'm trying create an immutable object and initialise it from xml config file in
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying create a scaling layout for an Android application. The whole screen should
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I'm trying create a small http proxy service. This is not working so well.
I'm currently trying create a service that will return results of a OLAP cube
I am trying create a layout. There are several inner layouts that should like
I am trying create system in which I can login from php and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.