2

I've got some TIF files in Azure Blob Storage. I'd like to display them in the browser via a link embedded in a spreadsheet. The simplest way to do this should be to take the file code as a request parameter and return the properly formatted HTML, right?

So right now I've got it returning a req.body with some HTML. Unfortunately, the HTML just shows up as a string in the browser. How do I make it render as HTML with minimal rigamarole?

Here's my code:

if (req.query.blob) {
    let blob = req.query.blob;
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: `<object width=200 height=200 
                data="<baseaddress>/${blob}.tif" type="image/tiff">
                <param name="src" value="<baseaddress>/${blob}.tif">
                <param name="negative" value="yes">
                </object>`
    };
}
Zanon
  • 29,231
  • 20
  • 113
  • 126
Boris K
  • 3,442
  • 9
  • 48
  • 87

1 Answers1

3

You need to set the headers to specify the content type to HTML and the response must be a full valid HTML page (with the <html> tag and the rest).

Example:

module.exports.hello = (event, context, callback) => {

  const html = `
    <!doctype html>
    <html>
      <head>
        <title>The Page Title</title>
      </head>
      <body>
        <h1>Hello</h1>
      </body>
    </html>`;

  const response = {    
    statusCode: 200, 
    headers: {
      'Content-Type': 'text/html'
    }, 
    body: html
  };

  callback(null, response);
};
Zanon
  • 29,231
  • 20
  • 113
  • 126