POST media/upload.json always returns “media parameter is missing"


I’m working on an image-posting script from within Google Apps Script, and I can’t seem to get posting to to work correctly.

After trying to build my own multipart form by concatenating all the bytes together, I’ve reduced the overhead to just one blob (type image/jpeg) in the payload. The options object looks like this:

var options = {
method: “POST”,
contentType: “multipart/form-data”,
payload: { “media[]” : imageblob }

where imageblob is a Blob (apps script type for handling binary data) containg the bin data for a JPEG and the image/jpeg content type.

One sample of the request object that’s created:
[14-11-20 06:23:11:240 PST]
“payload”:”-------wlinujDVABg2j6YW82NGhFaaNR5eDBAHsXqTWd1VmQHMTXtX7H\r\nContent-Disposition: form-data; name=“media[]”; filename=“edt35.jpg”\r\nContent-type: image/jpeg\r\n\r\n
[binary data truncated]

And what I get back is always:
{ "errors”: [{“code”:38,“message”:“media parameter is missing.”}]}

So I’ve tried every naming permutation (media, media[], media_data, media_data[]) and none of these produce any different an answer. The format of the form data being sent seems correct, so I am rather at a loss for what I’m doing wrong. Anyone dealt with this before?


Figured it out finally. Two things are important here:

  1. the parameter name has to be “media”, not “media[]”
  2. Do not set the contentType property. It prevents a Content-Type header with the correct boundary value from being automatically created.

A correct options object looks like this:
var options = {
method: “POST”,
payload: { “media” : imageblob }

Media upload (upload.json) endpoint

Glad you got it figured out—thanks for posting the solution, too, so others can benefit. Much appreciated.


Thank you. If anyone reading this would like to leverage my work, I’ve put together a simple Twitter library for Apps Script that includes searching, tweeting, and uploading media. Check it out at


I am trying to upload binary image directly…I am getting following error:
{“errors”:[{“message”:“Could not authenticate you”,“code”:32}]}

Can you please suggest me.