Я получаю следующую ошибку при запуске опубликованной версии моей функции, следует отметить, что при локальном запуске она работает правильно.
Доступ к пути 'D: \ Program Files
(x86) \ SiteExtensions \ Functions \ 1.0.12205 \ wkhtmltopdf 'запрещен. в
System.IO .__ Error.WinIOError (Int32 errorCode, String MaybeFullPath) в
System.IO.Directory.InternalCreateDirectory (String fullPath, String
путь, объект dirSecurityObj, логический checkHost) в
System.IO.Directory.InternalCreateDirectoryHelper (String path, Boolean
checkHost) в System.IO.Directory.CreateDirectory (String path) в
NReco.PdfGenerator.HtmlToPdfConverter.EnsureWkHtmlLibs () в
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal (WkHtmlInput []
htmlFiles, String inputContent, String coverHtml, String
outputPdfFilePath, Stream outputStream) в
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf (String htmlContent,
String coverHtml, Stream output) в
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf (String htmlContent,
Строка coverHtml) в
NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf (String htmlContent)
в HTMLtoPDF.Function1.d__0.MoveNext ()
Мое приложение в основном преобразует HTML в файл PDF, загружает в Azure и возвращает результат URI.
Как вы можете видеть в моем коде ниже, я не делаю никаких ссылок на этот путь.
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using NReco.PdfGenerator;
using System;
namespace HTMLtoPDF
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string pdfurl = "";
// parse query parameter
string html = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "html", true) == 0)
.Value;
if (html == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
html = data?.html;
}
try
{
HtmlToPdfConverter converter = new HtmlToPdfConverter();
var genpdf = converter.GeneratePdf(html);
var stream = new MemoryStream(genpdf, writable: false);
pdfurl = await UploadFileAsBlobAsync(stream, Guid.NewGuid()+".pdf");
}
catch (Exception ex)
{
pdfurl = ex.Message+Environment.NewLine+ex.InnerException;
}
return html == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass html on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, pdfurl);
}
public static async Task<string> UploadFileAsBlobAsync(Stream stream, string filehtml)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(HIDDENFORSECURITY);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("applicationimages");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(filehtml);
await blockBlob.UploadFromStreamAsync(stream);
stream.Dispose();
return blockBlob?.Uri.ToString();
}
}
}