Converting docx to html with dotnet-mammoth fails at deploy server

前提是你 提交于 2019-12-31 03:49:15

问题


I'm using dotnet-mammoth (mammoth.js with edge.js) to convert a docx document to html in .net
I added it to my project via its nuget package.

I'm using the code provided by the sample, which is working correctly in my development enviroment (running IIS Express):

var documentConverter = new Mammoth.DocumentConverter();
var result = documentConverter.ConvertToHtml(Server.MapPath("~/files/document.docx")); // problem here at production enviroment
string theResult = result.Value

However, once I deploy it to production server, when the executed code reaches documentConverter.ConvertToHtml() method, it's redirecting me to the login page. Without displaying any error messages, without saving anything on IIS log file.

If I remove that line, everything else executes normally. I assume it could be an issue related to permissions but I don't know what could it be. Any ideas?


回答1:


The latest version of Mammoth on NuGet no longer uses edge.js, and is now just .NET code, so should work more reliably.




回答2:


You can resolve this by getting the exact error when the process is trying to read the file. Below is the code from dotnet-mammoth DocumentConverter.cs. As shown below on call it is trying to read all bytes to be sent to edge

public Result<string> ConvertToHtml(string path)
        {
            var mammothJs = ReadResource("Mammoth.mammoth.browser.js") + ReadResource("Mammoth.mammoth.edge.js");

            var f = Edge.Func(mammothJs);
            var result = f(File.ReadAllBytes(path));
            Task.WaitAll(result);

            return ReadResult(result.Result);
        }

I suppose you are giving absolute path to the input. In that case the absolute path should be accessible by app identity hosting the app pool of the web application.

If the path specified is in web root directory - (not advised) - but if it is then you can use Server.MapPath



来源:https://stackoverflow.com/questions/31885962/converting-docx-to-html-with-dotnet-mammoth-fails-at-deploy-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!