From b9d7f50cc9cf0c02f21d2853906f7132945900b8 Mon Sep 17 00:00:00 2001 From: RakVhalate Date: Wed, 2 Nov 2022 01:45:42 +1000 Subject: [PATCH] some scretches about file upload --- Controllers/PictureUpload.cs | 19 +++++++++++++++++++ DBchat.cs | 5 +++-- NeDvachAPI.csproj.user | 2 +- Post.cs | 7 +------ Program.cs | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 Controllers/PictureUpload.cs diff --git a/Controllers/PictureUpload.cs b/Controllers/PictureUpload.cs new file mode 100644 index 0000000..b5b65b6 --- /dev/null +++ b/Controllers/PictureUpload.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using System.Net.Http.Headers; +using System.Text.Json; + +namespace NeDvachAPI.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UploadPic : ControllerBase + { + [HttpPost(Name = "UploadPicture")] + public JsonResult ReceivePost([FromForm] IFormFile PostPicture) + { + Console.Write("Принята картинка "); + Console.WriteLine(PostPicture.FileName); + return new JsonResult(PostPicture.FileName + " получен!"); + } + } +} diff --git a/DBchat.cs b/DBchat.cs index 6e2b376..92c5700 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -46,7 +46,7 @@ namespace NeDvachAPI using ( var command = new NpgsqlCommand(@" SELECT * FROM ( - SELECT post_id, post, post_timestamp + SELECT post_id, post, post_timestamp, post_pic FROM dvach ORDER BY post_id DESC ) subquery @@ -67,7 +67,8 @@ namespace NeDvachAPI { Id = reader.GetInt32(0), Text = reader.GetString(1), - Timestamp = reader.GetString(2) + Timestamp = reader.GetString(2), + ImgURL = (string)reader.GetString(3) }; posts.Add(receivedPost); //posts[postCount] = receivedPost; diff --git a/NeDvachAPI.csproj.user b/NeDvachAPI.csproj.user index fa6d545..e4f6e71 100644 --- a/NeDvachAPI.csproj.user +++ b/NeDvachAPI.csproj.user @@ -1,7 +1,7 @@  - MvcControllerWithActionsScaffolder + MvcControllerEmptyScaffolder root/Common/MVC/Controller \ No newline at end of file diff --git a/Post.cs b/Post.cs index fb47b2b..8e083e7 100644 --- a/Post.cs +++ b/Post.cs @@ -7,12 +7,7 @@ namespace NeDvachAPI public int Id { get; set; } public string Text { get; set; } - } - public class ReceivedValues - { - public string height { get; set; } - - public string altitude { get; set; } + public string ImgURL { get; set; } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index dacd95a..237fdf6 100644 --- a/Program.cs +++ b/Program.cs @@ -12,8 +12,8 @@ builder.Services.AddCors(setup => setup.AddDefaultPolicy(policyBuilder => { - policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*"); - //policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*"); + //policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*"); + policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*"); }); });