1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

create org with license file

This commit is contained in:
Kyle Spearrin
2017-08-14 20:57:45 -04:00
parent e4ec09fd0c
commit 5259b07889
9 changed files with 146 additions and 60 deletions

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System.IO;
using System.Threading.Tasks;
namespace Bit.Api.Utilities
{
public static class ApiHelpers
{
public async static Task<T> ReadJsonFileFromBody<T>(HttpContext httpContext, IFormFile file, long maxSize = 51200)
{
T obj = default(T);
if(file != null && httpContext.Request.ContentLength.HasValue && httpContext.Request.ContentLength.Value <= maxSize)
{
try
{
using(var stream = file.OpenReadStream())
using(var reader = new StreamReader(stream))
{
var s = await reader.ReadToEndAsync();
if(!string.IsNullOrWhiteSpace(s))
{
obj = JsonConvert.DeserializeObject<T>(s);
}
}
}
catch { }
}
return obj;
}
}
}