我正在使用 azure 函数使用 jimp 生成缩略图。我面临的挑战是 azure 容器上的内容类型最终是 application/octet-stream 而不是 image/jpeg。如何解决这个问题?
这是代码:
var Jimp = require("jimp");
module.exports = (context, myBlob) => {
// Read image with Jimp
Jimp.read(myBlob).then((image) => {
// Manipulate image
image
.resize(200, 200)
.getBuffer( Jimp.MIME_JPEG, (error, stream) => {
// Check for errors
if (error) {
context.log(`There was an error processing the image.`);
context.done(error);
}
else {
context.log(`Successfully processed the image`);
context.bindingData.properties = {contentType: Jimp.MIME_JPEG}
// Bind the stream to the output binding to create a new blob
context.done(null, stream);
}
});
});
};