title: Attaching a file using Resumable upload w/ Gmail API
body: <p>I am attempting to use Gmail's Resumable option for uploading attachments to an email. Documentation reference: <a href="https://developers.google.com/gmail/api/guides/uploads#resumable" rel="nofollow noreferrer">https://developers.google.com/gmail/api/guides/uploads#resumable</a>.</p>
  
  <p>Currently I am able to send the email with the resumable URI, but without an attachment (using Postman). Documentation doesn't provide very clear examples of what the request should specifically look like, and there don't seem to be many examples after scouring the internet.</p>
  
  <p>My requests are in two parts:</p>
  
  <ol>
  <li><p>Initial request -</p>
  
  <pre><code>Request URL:
  POST /upload/gmail/v1/users/me/messages/send?uploadType=resumable
  Host: www.googleapis.c om (can't post links so I interrupted the url)
  
  Headers: 
  Authorization: Bearer my_token_here
  Content-Length: 113
  Content-Type: application/json
  X-Upload-Content-Length: 67
  X-Upload-Content-Type: message/rfc822
  
  Body:
  {"raw":"VG86IG5pcnZhbmEucm9ja2VyQGdtYWlsLmNvbQpTdWJqZWN0OiBUZXN0RW1haWxTdWJqZWN0MwoKTWVzc2FnZSBjb250ZW50cyAjMy4"}
  </code></pre></li>
  </ol>
  
  <p>The body is a 64bit encoded string that include the To, Subject, and email message contents. Then gmail returns a response with an empty body, and a 'location' header that looks like the following:  googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=resumable&amp;upload_id=BRnB2UoAsKwzNMoQAy-JtmP6mu5agltqOWZ9uerI3k-KNTDJ73PWEjKuAHpko4RN6weSEysddH2kjj4G24uFw6E9oPv1XP69l7_KcmNuW-RAoz_5oS1T_4_E. (removed https:// because this account can only have one link in a post)</p>
  
  <p>I then follow up with a PUT request to that URL returned in the location header.</p>
  
  <ol start="2">
  <li><p>The second request looks like the following:</p>
  
  <pre><code>Request URL: 
  PUT /upload/gmail/v1/users/me/messages/send?uploadType=resumable&amp;upload_id=BRnB2UoAsKwzNMoQAy-JtmP6mu5agltqOWZ9uerI3k-KNTDJ73PWEjKuAHpko4RN6weSEysddH2kjj4G24uFw6E9oPv1XP69l7_KcmNuW-RAoz_5oS1T_4_E
  Host: www.googleapis.c om
  
  Headers: 
  Content-Length: 67
  Content-Type: message/rfc822
  
  Body:
  {"raw":"VG86IG5pcnZhbmEucm9ja2VyQGdtYWlsLmNvbQpTdWJqZWN0OiBUZXN0RW1haWxTdWJqZWN0MwoKTWVzc2FnZSBjb250ZW50cyAjMy4"}
  --- OR ---
  I choose the binary option, and attach the file I am looking to upload via Postman.
  </code></pre></li>
  </ol>
  
  <p>I receive a response from Gmail with an object like this:</p>
  
  <pre><code>    {
        "id": "159d7ded3125e255",
        "threadId": "159d7ded3125e255",
        "labelIds": [
          "SENT"
        ]
      }
  </code></pre>
  
  <p>And an email is sent successfully, however there isn't an attachment with the email. When I show the original email in Gmail, there isn't any evidence of an attachment. Original looks like the following:</p>
  
  <pre><code>    Received: from 325276275830 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Jan 2017 15:03:33 -0800
      To: some.name@gmail.com
      Subject: TestEmailSubject3
      Date: Wed, 25 Jan 2017 15:03:33 -0800
      Message-Id: &lt;CEROA6F=0ohk33RD9XyC_gW1DZO88xYF4bXYqrCSct62MUuytDw@mail.gmail.com&gt;
      From: name_here@gmail.com
  
      Message contents #3.
  </code></pre>
  
  <p>What am I missing? Do I need to encode some particular contents in a different way, or put some data in a different location? I'm not receiving any errors. I've been working on this for a few days now and I just can't figure it out.</p>