设置缩略图图像内容types

我需要为缩略图图像设置Content-Type 。 我尝试过,如下图所示。但它不起作用。但是,它存储为一个stream。

在这里输入图像说明

天青function:

index.json

 var Jimp = require("jimp"); module.exports = (context, myBlob) => { // Read image with Jimp Jimp.read(myBlob).then((image) => { // Manipulate image image .resize(200, Jimp.AUTO) .greyscale() .getBuffer(Jimp.MIME_JPEG, (error, stream) => { if (error) { context.log(`There was an error processing the image.`); context.done(error); } else { context.log(`Successfully processed the image`); stream.set("Content-Type", Jimp.MIME_JPEG); // here need to set the Content-Type context.done(null, stream); } }); }); }; 

function.json

 { "bindings": [ { "name": "myBlob", "type": "blobTrigger", "direction": "in", "path": "project2-photos-original/{name}", "connection": "thumbnailfunction_STORAGE", "dataType": "binary" }, { "type": "blob", "name": "$return", "path": "project2-photos-thumbnail/{name}", "connection": "thumbnailfunction_STORAGE", "direction": "out" } ], "disabled": false } 

我在NodeJs上看到过这样的实现

 var Jimp = require("jimp"); var express = require("express"); var app = express(); app.get("/my-dynamic-image", function(req, res){ Jimp.read("lenna.png", function(err, lenna) { lenna.resize(64, 64).quality(60).getBuffer(Jimp.MIME_JPEG, function(err, buffer){ res.set("Content-Type", Jimp.MIME_JPEG); res.send(buffer); }); }); }); app.listen(3000); 

问:你能告诉我如何在Azurefunction上设置Content-Type吗?

PS我不是一个Nodejs开发人员。

编辑:

不幸的是,节点的blob输出绑定不支持设置内容types。 一个select是放弃输出绑定,并在你的节点函数中使用azure色的存储sdk ,它应该给你你需要的控制。

如果使用Http触发器和输出绑定:

类似expression式的“res”对象可以通过content.res来访问,所以不需要stream.set ,而需要context.res.set / context.res.type 。 在getBuffercallback中返回的stream对象是一个缓冲区,而不是一个stream,并且与http响应无关。

需要注意的一点是,azure函数不支持从节点返回stream – 你需要有整个缓冲区(幸运的是,getBuffer似乎返回!)

这是一个getBuffercallback:

 function(err, buffer){ if (err) { context.log("There was an error processing the image."); context.done(err); } else { context.log("Successfully processed the image"); // set content type to Jimp.MIME_JPEG context.res.type(Jimp.MIME_JPEG) // send the raw response (don't apply any content negotiation) context.res.raw(buffer); } });