I am getting a permission denied when trying to stream a pdf file to the browser. I have set the read, write and execute permissions for the temp folder in the DockerFile. Any pointers on what I be doing wrong? I am hosting the ASP.Net Core application as a Azure App service and docker Linux container, if that matters.
StackTrace:
Exception occured: Syncfusion.Pdf.PdfException: /usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: /app/QtBinariesLinux/Syncfusion.WebKitWrapper: Permission denied
at Syncfusion.HtmlConverter.HtmlConverter.ConvertHtmlToPdf(String url, Int32 width, Int32 height)
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
RUN chmod a+rwx -R /usr/bin/xvfb-run
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Scrubber/Scrubber.csproj", "Scrubber/"]
COPY ["SimplerProducts.MicrosoftEntityFrameworkCoreStorage/SimplerProducts.MicrosoftEntityFrameworkCoreStorage.csproj", "SimplerProducts.MicrosoftEntityFrameworkCoreStorage/"]
RUN dotnet restore "Scrubber/Scrubber.csproj"
COPY . .
WORKDIR "/src/Scrubber"
RUN dotnet build "Scrubber.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Scrubber.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Scrubber.dll"]
CSharp code:
public IActionResult OnPostExportToPDFAsync()
{
var htmlToPdfConverter = new HtmlToPdfConverter
{
ConverterSettings = new WebKitConverterSettings
{
WebKitPath = Path.Combine(HostingEnvironment.ContentRootPath, "QtBinariesLinux"),
TempPath = Path.GetTempPath(),
SplitTextLines = false,
SplitImages = false,
EnableRepeatTableHeader = true,
EnableRepeatTableFooter = true,
}
};
var pdfDocument = htmlToPdfConverter.Convert("http://www.google.com");
var memoryStream = new MemoryStream();
pdfDocument.Save(memoryStream);
return File(memoryStream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Sample.pdf");
}
This was more of a Azure issue rather than a Docker or file permissions issue. I was able to fix the issue by changing the Azure resource group from F1-Free to S1-Basic, for the App Service.