我很难重新创建this例子。我得到以下输出:
2019-08-19T17:19:24.531 [Information] Executing 'Functions.PdfToTiffConverter' (Reason='EventGrid trigger fired at 2019-08-19T17:19:24.4859961+00:00', Id=161802cf-f5b9-4555-8e36-a9ca7e0daf91) 2019-08-19T17:20:26.112 [Information] Error: w and h must be numbers at Jimp.throwError (D:\home\site\wwwroot\node_modules@jimp\utils\dist\index.js:26:13) at Jimp.resize (D:\home\site\wwwroot\node_modules@jimp\plugin-resize\dist\index.js:38:36) at Jimp.read.then (D:\home\site\wwwroot\PdfToTiffConverter\index.js:14:19)
这是我的function.json
:
{
"disabled": false,
"bindings": [
{
"type": "eventGridTrigger",
"name": "myEvent",
"direction": "in"
},
{
"name": "myBlob",
"type": "blob",
"direction": "in",
"path": "{data.url}",
"connection": "AZURE_STORAGE_CONNECTION_STRING",
"datatype": "binary"
}
]
}
这是我正在使用的代码:
const stream = require('stream');
const Jimp = require('jimp');
const storage = require('azure-storage');
const blobService = storage.createBlobService();
module.exports = (context, myEvent, myBlob) => {
const widthInPixels = process.env.THUMBNAIL_WIDTH;
const blobName = myEvent.subject.split('/')[6];
Jimp.read(myBlob).then((thumbnail) => {
thumbnail.resize(widthInPixels, Jimp.AUTO);
thumbnail.getBuffer(Jimp.MIME_PNG, (err, buffer) => {
const readStream = stream.PassThrough();
readStream.end(buffer);
blobService.createBlockBlobFromStream('thumbnails', blobName, readStream, buffer.length, (err) => {
context.done();
});
});
}).catch(context.log);
};
我做错了什么?为什么我会遇到此异常?
最佳答案
就像@Pointy指出的那样,process.env.THUMBNAIL_WIDTH的值是一个字符串,而不是数字。
尝试使用const widthInPixels = Number(process.env.THUMBNAIL_WIDTH);
关于javascript - w 和 h 必须是数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57561531/