0

We just upgraded our 2sxc custom API to v14, and now we're having an issue in an API controller that's used for uploading files with converting from Base64 to a byte array. Here's the code:

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;
    }
}

We're getting the following error now:

{
    "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"
}

Any ideas how to fix this? I did try changing "Convert.FromBase64String" to "System.Convert.FromBase64String" and that didn't solve the issue - I got a "Cannot perform runtime binding on a null reference" error instead.

Any help would be greatly appreciated!

John K.
  • 98
  • 9

1 Answers1

0

System.Convert... sounds right. And IMHO should work.

My guess is that your bodyJson or bodyJson.file is null.

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21