iformfile

C# IFormFile as ZipFile

可紊 提交于 2019-12-24 18:31:13
问题 I have a REST API endpoint which receives zip file on .Net Core 1.1. I'm getting IFormFile from request like this var zipFile = HttpContext.Request.Form.Files.FirstOrDefault(); And then I need to pass it to service method from .Net Standard 1.5, where IFormFile is not supported. So the question is: how can I convert IFormFile to ZipFile or to some other type which is supported in Standard 1.5, or maybe there is some more proper way to operate with zip files? Thanks! 回答1: IFormFile is just a

How to save Images to database using ASP.NET Core?

自作多情 提交于 2019-12-19 05:24:05
问题 I am working on a small blog using ASP.NET Core(MVC 6) EF Visual Studio. I have trouble finding how to save images to a database. I have read about IFormfile but I do not really understand how to go about it, I am stuck. I am new to this and would love to have a little help. I want to save the image to the post I am creating(In the same form). I, therefore, want to save it to postID. Then I need to be able to display the image, how do I do that? I know there is a lot to ask, but I do not know

FromForm with IFormFile using Asp.net Core

♀尐吖头ヾ 提交于 2019-12-14 04:11:28
问题 I want to upload an Image file with Model data so I am using FromForm with IFormFile in Asp.net core api. [HttpPost] public IActionResult AddData([FromForm] AddDataModel addDataModel, IFormFile formFile) { // Logic here... } I am using Angular 7 in the frontend side. I am adding model data and file to FormData and trying to send it but It always all model fields values null. What is the right way to solve this? 回答1: The formfile has to be inside your AddDataModel csharp class. Like this

How to parse byte[] array from model with IFormFile from viewmodel for file uploading controller?

∥☆過路亽.° 提交于 2019-12-11 13:35:09
问题 I have Core MVC application, when for specific entity I have following model: public class Aktualnosci { public long ID { get; set; } public string Tytul { get; set; } public string Tresc { get; set; } public DateTime Dzien { get; set; } public byte[] AktualnosciImage { get; set; } } For uploading the image I am using IFormFile property in my viewmodel, that is called by controller, according to the documentation from >>HERE<<: public class AktualnosciCreateVM { public long ID { get; set; }

.net core 2.1 “POST” an IFormFile using Postman - the application completed without reading the entire request body

末鹿安然 提交于 2019-12-10 18:38:00
问题 I'm working on a dotnet core WebAPI 2.1 and I can't find a way of sending to into the Body an image. The controller looks like this: [HttpPost("api/image")] public IActionResult Post([FromBody]IFormFile file) { var filePath = Path.GetTempFileName(); if (file.Length > 0) { return Ok(); } return BadRequest(); } And this is my Postman call: This call is never finishing as the Kestrel is failing I've already tried to use Consumes [Consumes("application/json", "application/json-patch+json",

Submitting multiple files to ASP.NET controller accepting an ICollection<IFormFile>

落爺英雄遲暮 提交于 2019-11-30 15:32:32
问题 In my ASP.NET Core backend, I have a controller function that looks like this: [HttpPost] [Route("documents/upload")] public async Task<IActionResult> UploadFile(ICollection<IFormFile> files) { ... } In my front-end, I call the function like this: var postSettings = { method: 'POST', credentials: 'include', mode: 'cors' } uploadDocuments( files ) { var data = new FormData(); data.append('files', files); postSettings.body = data; return fetch(endPoint + '/documents/upload', postSettings); } If

How to instantiate an instance of FormFile in C# without Moq?

♀尐吖头ヾ 提交于 2019-11-29 19:06:23
问题 I want to test a function that attaches files to documents in a RavenDB database with an integration test. For this, I need an instance of IFormFile . Obviously, I can't instantiate from an interface so I tried to instantiate an instance of FormFile which inherits from the IFormFile interface. using (var stream = File.OpenRead("placeholder.pdf")) { var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) { ContentType = "application.pdf" }; } But this throws the