Skip to content

Commit

Permalink
move to uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 15, 2018
1 parent 56a1f82 commit 76b6860
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,7 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs


uploads/*
Thumbs.db
19 changes: 11 additions & 8 deletions theiacore/theiacore/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ApiController(IHostingEnvironment hostingEnvironment)
}


public async Task<IActionResult> Post(List<IFormFile> files)
/*public async Task<IActionResult> Post(List<IFormFile> files)
{
long size = files.Sum(f => f.Length);
Expand All @@ -47,7 +47,7 @@ public async Task<IActionResult> Post(List<IFormFile> files)
// Don't rely on or trust the FileName property without validation.
return Ok(new {count = files.Count, size, filePath});
}
}*/

[HttpPost]
[ValidateAntiForgeryToken]
Expand All @@ -64,23 +64,25 @@ public async Task<IActionResult> UploadFile(IFormFile file)
return BadRequest("file not selected");

var path = Path.Combine(
Directory.GetCurrentDirectory(),
Directory.GetCurrentDirectory(),"uploads",
guid);

Console.WriteLine(path);

using (var stream = new FileStream(path, FileMode.Create))
{
await file.CopyToAsync(stream);
}

using (Image img = Image.FromFile(guid))
using (Image img = Image.FromFile(path))
{
if (!img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
return BadRequest("wrong format");
}
}

return Json(GetTensorObject.GetJsonFormat(guid));
return Json(GetTensorObject.GetJsonFormat(path));
}


Expand All @@ -97,20 +99,21 @@ public async Task<IActionResult> Upload()
// todo: check apikey

var guid = DateTime.UtcNow.ToString("yyyyddMM_HHmmss__") + Guid.NewGuid().ToString().Substring(0, 20) + ".jpg";
using (var stream = System.IO.File.Create(Path.Combine(_hostingEnvironment.ContentRootPath, guid)))
var path = Path.Combine(_hostingEnvironment.ContentRootPath, "uploads", guid);
using (var stream = System.IO.File.Create(path))
{
await Request.StreamFile(stream);
}

using (Image img = Image.FromFile(guid))
using (Image img = Image.FromFile(path))
{
if (!img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
return BadRequest("wrong format");
}
}

var tensorObject = GetTensorObject.GetJsonFormat(guid);
var tensorObject = GetTensorObject.GetJsonFormat(path);

if (IsKeyOptOutAnalytics(Request))
{
Expand Down
9 changes: 8 additions & 1 deletion theiacore/theiacore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public void ConfigureServices(IServiceCollection services)
services.AddMvc();
services.AddSingleton<IFileProvider>(
new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")));
Path.Combine(Directory.GetCurrentDirectory())));

if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "uploads")))
{
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "uploads"));
}



}

Expand Down

0 comments on commit 76b6860

Please sign in to comment.