Edited Thank you @Marco
I'm trying to write a function app that grabs an SVG from a URL and converts it to PNG. I know there are existing API's that do this like CloudConvert, but they don't work nicely with embedded fonts, which is a requirement for me.
Anyway, I wrote a very basic function app that simply downloads a file at this point. Everything works perfectly fine locally, but when I publish to Azure, I get An exception occurred during a WebClient request.
Thanks to @Marco's suggestion, I switched from WebClient to HTTPWebRequest to get more detailed error handling, and as a result, I see the following:
2018-10-11T13:53:53.558 [Info] Function started (Id=e3cbda04-140e-4ef7-ad6c-c871ffe179dd)
2018-10-11T13:53:53.590 [Info] C# HTTP trigger function processed a request. 2018-10-11T13:53:53.752 [Info] Download Fail
2018-10-11T13:53:53.752 [Info] Access to the path
'D:\Windows\system32\734e16961fc276df.svg' is denied.
Am I trying to do something that isn't possible, or is there a fix for this? Is there a way to configure permissions in an Azure function? I need to pull the file down to edit and not just work with the byte array.
Many thanks!
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req,
TraceWriter log, ExecutionContext context)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string svgURL = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "l", true) == 0)
.Value;
if (svgURL == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
svgURL = data?.svgURL;
}
// download file from URL
var uniqueName = GenerateId() ;
try
{
using (var client = new WebClient())
{
client.DownloadFile(svgURL, uniqueName + ".svg" );
}
}
catch (Exception e)
{
log.Info("Download Fail");
log.Info(e.Message);
}
}
HttpWebRequest
instead of aWebClient
to see if you get any more detailed exception messages / Stacktraces. – MarcoHttpWebRequest
now – Mike BaronsvgUrl
is def. not null in production. Because currently it defintily can be. – Marco