我们刚刚将我们的2sxc自定义API升级为v14,现在我们在一个API控制器中遇到了一个问题,该控制器用于将文件从Base64转换为字节数组来上传文件。下面是代码:
public class IntegrationApiController : Custom.Hybrid.Api14
{
[HttpPost]
public string UploadPdf([FromBody] dynamic bodyJson)
{
var entity = new Dictionary<string, object>();
var guid = Guid.NewGuid();
entity.Add("EntityGuid", guid);
App.Data.Create("PDFForm", entity);
var data = Convert.FromBase64String(bodyJson.file.ToString());
var returnThing = SaveInAdam(stream: new MemoryStream(data), fileName: bodyJson.fileName.ToString(), contentType: "PDFForm", guid: guid, field: "File");
return returnThing.Url;
}
}我们现在得到以下错误:
{
"Message": "2sxc Api Controller Finder Error: Error selecting / compiling an API controller. Check event-log, code and inner exception. ",
"ExceptionMessage": "c:\\Websites\\Mainstar\\Portals\\0\\2sxc\\DocusignForms\\api\\IntegrationApiController.cs(26): error CS1061: 'ToSic.Sxc.Services.IConvertService' does not contain a definition for 'FromBase64String' and no extension method 'FromBase64String' accepting a first argument of type 'ToSic.Sxc.Services.IConvertService' could be found (are you missing a using directive or an assembly reference?)",
"ExceptionType": "System.Web.HttpCompileException",
"StackTrace": " at System.Web.Compilation.AssemblyBuilder.Compile()\r\n at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()\r\n at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)\r\n at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)\r\n at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)\r\n at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)\r\n at System.Web.Compilation.BuildManager.GetCompiledAssembly(String virtualPath)\r\n at ToSic.Sxc.Dnn.WebApiRouting.AppApiControllerSelector.HttpControllerDescriptor(HttpRequestMessage request, String controllerFolder, String controllerPath, String controllerTypeName, LogCall`1 wrapLog) in C:\\Projects\\2sxc\\2sxc\\Src\\Dnn\\ToSic.Sxc.Dnn.WebApi\\Dnn\\WebApiRouting\\AppApiControllerSelector.cs:line 168\r\n at ToSic.Sxc.Dnn.WebApiRouting.AppApiControllerSelector.SelectController(HttpRequestMessage request) in C:\\Projects\\2sxc\\2sxc\\Src\\Dnn\\ToSic.Sxc.Dnn.WebApi\\Dnn\\WebApiRouting\\AppApiControllerSelector.cs:line 83"
}有什么办法解决这个问题吗?我确实尝试过将"Convert.FromBase64String“更改为"System.Convert.FromBase64String”,但这并没有解决问题--我得到了一个“无法对空引用执行运行时绑定”的错误。
任何帮助都将不胜感激!
发布于 2022-09-28 14:06:56
System.Convert...听起来是对的。而国际水文学组织应该发挥作用。
我猜您的bodyJson或bodyJson.file是空的。
https://stackoverflow.com/questions/73870725
复制相似问题