C# ';此图像格式的NodeCodeDeleteGate';-AWS Lambda无服务器API中的Magick.NET
我正在使用Magick.NET调整图像大小并将其保存到AWS S3。我有一个Lambda无服务器Web API,它接受执行此操作的请求。它在本地运行时工作正常,但在Lambda上调用活动端点时工作不正常。我得到以下例外情况:C# ';此图像格式的NodeCodeDeleteGate';-AWS Lambda无服务器API中的Magick.NET,c#,amazon-web-services,asp.net-core,aws-lambda,imagemagick,C#,Amazon Web Services,Asp.net Core,Aws Lambda,Imagemagick,我正在使用Magick.NET调整图像大小并将其保存到AWS S3。我有一个Lambda无服务器Web API,它接受执行此操作的请求。它在本地运行时工作正常,但在Lambda上调用活动端点时工作不正常。我得到以下例外情况: { "Timestamp": "2018-08-31T09:26:40.2561647+00:00", "Level": "Error", "MessageTemplate": "### Error resizing image. ###",
{
"Timestamp": "2018-08-31T09:26:40.2561647+00:00",
"Level": "Error",
"MessageTemplate": "### Error resizing image. ###",
"Exception": "ImageMagick.MagickMissingDelegateErrorException: NoDecodeDelegateForThisImageFormat `' @ error/blob.c/BlobToImage/456\n at TAP.Services.TourManagementService.<AddImage>d__24.MoveNext() in C:\\######\\TourManagementService.cs:line 180\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at TAP.API.Tours.Controllers.ImagesController.<Post>d__3.MoveNext() in C:\\######\\ImagesController.cs:line 44\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()",
"Properties": {
"ExceptionDetail": {
"HResult": -2146233088,
"Message": "NoDecodeDelegateForThisImageFormat `' @ error/blob.c/BlobToImage/456",
"Source": "Magick.NET-Q16-AnyCPU",
"RelatedExceptions": [
{
"RelatedExceptions": [],
"Message": "UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/714",
"Data": {},
"InnerException": null,
"TargetSite": null,
"StackTrace": null,
"HelpLink": null,
"Source": null,
"HResult": -2146233088
}
],
"Type": "ImageMagick.MagickMissingDelegateErrorException"
}
}
}
我以前在尝试读取本地文件时遇到过Lambda问题,因此我认为UnableToOpenConfigureFile
可能也是一个类似的问题。然后,我使用GitHub指南()使用代码初始化MagickNET,而不是依赖.xml文件,如下所示:
var configFiles = ConfigurationFiles.Default;
configFiles.Policy.Data = @"
<policymap>
<policy domain=""delegate"" rights=""none"" pattern=""*"" />
<policy domain=""coder"" rights=""none"" pattern=""*"" />
<policy domain=""coder"" rights=""read|write"" pattern=""{GIF,JPEG,PNG,WEBP}"" />
</policymap>";
MagickNET.Initialize(configFiles);
这也无法帮助我。缺少其他XML配置文件。尝试用lambda解决方案打包XML,并将
MAGICK\u CONFIGURE\u PATH
环境变量设置为文件的位置。感谢回复@emcconville。我刚试过,可惜没用。有关详细信息,请参见上面的编辑。
var configFiles = ConfigurationFiles.Default;
configFiles.Policy.Data = @"
<policymap>
<policy domain=""delegate"" rights=""none"" pattern=""*"" />
<policy domain=""coder"" rights=""none"" pattern=""*"" />
<policy domain=""coder"" rights=""read|write"" pattern=""{GIF,JPEG,PNG,WEBP}"" />
</policymap>";
MagickNET.Initialize(configFiles);
MagickNET.Initialize("./MagickNet");