Skip to content

Instantly share code, notes, and snippets.

@rogeralsing
Created March 15, 2019 10:06
Show Gist options
  • Save rogeralsing/339617c7497bb7ed115d19fa41508816 to your computer and use it in GitHub Desktop.
Save rogeralsing/339617c7497bb7ed115d19fa41508816 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
namespace Bonliva
{
public static class MyHttpTriggerDemo
{
[FunctionName("MyHttpTriggerDemo")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var provider = new MultipartMemoryStreamProvider();
await req.Content.ReadAsMultipartAsync(provider);
var file = provider.Contents.First();
var fileInfo = file.Headers.ContentDisposition;
var fileData = await file.ReadAsByteArrayAsync();
string tempDir = Path.Combine(Path.GetTempPath(), "MyData");
if (!Directory.Exists(tempDir))
{
Directory.CreateDirectory(tempDir);
}
string tempFile = Path.Combine(tempDir, "test.txt");
File.WriteAllBytes(tempFile, fileData);
File.Delete(tempFile);
return new OkObjectResult($"Nice!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment