title: Azure function to load a blob and send it directly to context.res
body: <p>I thought it would be quite easy to load a blob from an azure storage container and write it to the HTTP response, but I'm not able to get it working.</p>
  
  <p>I've declared an input blob like this:</p>
  
  <pre><code>{
    "bindings": [
      {
        "authLevel": "function",
        "type": "httpTrigger",
        "direction": "in",
        "name": "req",
        "route": "resizeImage"
      },
      {
        "type": "http",
        "direction": "out",
        "name": "res"
      },
      {
        "type": "blob",
        "name": "imageBlob",
        "path": "images/{name}",
        "connection": "ng1_STORAGE",
        "direction": "in"
      }
    ],
    "disabled": false
  }
  </code></pre>
  
  <p>This is an HTTP trigger, so I just call the URL <code>resizeImage?name=image1.png</code> and that provides me with <code>context.bindings.imageBlob</code> as the blob data.</p>
  
  <p>However first problem is the blob is the wrong size. I've tried outputting JSON for <code>imageBlob.length</code> with the following two images:</p>
  
  <p>1) cat.png = 272228 bytes on disk, but imageBlob.length = 258032 bytes
  2) dog.png = 15699604 bytes on disk, but imageBlob.length = 15173390 bytes</p>
  
  <p>So</p>
  
  <ul>
  <li>I definitely know the file is being found and loaded because these image sizes are close to what they're supposed to be</li>
  <li>I'm guessing <code>imageBlob</code> is some kind of stream object? (I see the C# signature is Stream). </li>
  <li>Why is the .length property only giving me about 95% of the image size on disk?</li>
  </ul>
  
  <p>If I try to return it as-is like this then I get a content-length of <code>imageBlob.length</code>, but of course the image is incomplete.</p>
  
  <pre><code>context.res = {
                body: new Buffer(context.bindings.imageBlob, 'binary'),
  
                headers: {
                   'Content-Type': 'image/png'
                }
  </code></pre>
  
  <p>I will be using the sharp image library to process it, but I can't even right now return the original image! How do I just return the blob as an HTTP response?</p>