title: Microsoft Graph API Attachment handling
body: <p>I seem to be having problems decoding attachments from MS Graph API. At least, that's what I think the problem is. Below is a simple JS Sample.</p>
  
  <pre><code>        local.downloadAttachment = function (data) {
              $.get("https://graph.microsoft.com/v1.0/me/messages/" + self.EmailID() + "/attachments/" + data.id, null, function (results) {
                  var bytes = new Uint8Array(results.contentBytes); // pass your byte response to this constructor
                  var blob = new Blob([bytes], { type: results.contentType });// change resultByte to bytes
  
                  //Alt method, also doesn't work but seems a lot closer to the right solution.
                  //var altBytes = $.base64.decode(results.contentBytes);
                  //var blob = new Blob([altBytes], { type: results.contentType });
  
                  var link = document.createElement('a');
                  link.href = window.URL.createObjectURL(blob);
                  link.download = results.name;
                  link.click();
              });
          };
  </code></pre>
  
  <p>I've noticed a couple oddities. The contentType seems to be wrong, PDFs are typed as <em>application/octet-stream</em> I would have expected <em>application/pdf</em>. JPEG images appear to be typed correctly, however, I don't think this is the problem.</p>
  
  <p>I've tried using atob when decoding and using /$results to receive the file content in binary form.</p>
  
  <p>Any ideas would be great.</p>