Questions tagged [iformfile]
173 questions
49
votes
1 answer
How to instantiate an instance of FormFile in C# without Moq?
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…

Tom Aalbers
- 4,574
- 5
- 29
- 51
21
votes
3 answers
How to save Images to database using ASP.NET Core?
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…

ErikLm
- 401
- 1
- 6
- 12
14
votes
1 answer
Submitting multiple files to ASP.NET controller accepting an ICollection
In my ASP.NET Core backend, I have a controller function that looks like this:
[HttpPost]
[Route("documents/upload")]
public async Task UploadFile(ICollection files)
{
...
}
In my front-end, I call the function like…

Simon Christiansen
- 619
- 1
- 6
- 17
12
votes
5 answers
.net core 2.1 "POST" an IFormFile using Postman - the application completed without reading the entire request body
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 =…

rm -rf .
- 473
- 1
- 4
- 14
8
votes
3 answers
C# read IFormFile into byte[]
I am trying to read an IFormFile received from a HTTP POST request like this:
public async Task UploadDocument([FromForm]DataWrapper data)
{
IFormFile file = data.File;
string fileName = file.FileName;
long…

Eutherpy
- 4,471
- 7
- 40
- 64
8
votes
1 answer
There is any difference in uploading IFormFile vs Base64 string in .netcore web api?
I'm using .net core web api to accept, upload and download the file content.
I've already tried IFormFile and simple base64 encoded file content
UploadFile(IFormFile file)
UploadFile([FromBody] string base64Filecontentstring)
I'm just wondering if…

Yaroslav Smoliak
- 143
- 1
- 7
7
votes
1 answer
Is it possible to store Images other than wwwroot folder
I stored Images In a folder name "Images" which is not in wwwroot folder.
So now i am unable to access it so my question is that
How to give access to folder which contain images and thats folder is not the sub-folder of wwwroot? Or Its compulsory …

Ahmad Qasim
- 452
- 1
- 8
- 26
6
votes
0 answers
JsonSerializationException due to IFormFile
So long story short I have a view where Im using
@using (Html.BeginForm("AddFormToOrder", "Form", FormMethod.Post, new { @id = "OrderForm", enctype = "multipart/form-data" }))
which will have a file upload where once I select the files and click…

JDawg848
- 121
- 2
- 10
6
votes
1 answer
ASP.NET Core Web API IFormFile Empty, When sending FormData request
I am using Aurelia Fetch Client to send a File Upload request to a Web API endpoint. But the IFormFile is empty all the tile. My code is below.
Client Side
const formData = new FormData();
formData.append("files", account.statement);
const response…

Priyan Perera
- 560
- 1
- 7
- 20
6
votes
1 answer
ASP.NET Core MVC base64 image to IFormFile
I have a problem. I stored some images in DB as base64, and now I need to edit this object that contains this image. The image is uploaded by the user in a form and I converted it to base64 and stored it in DB. Now my problem is how to convert…

Wasyster
- 2,279
- 4
- 26
- 58
5
votes
1 answer
Trying to convert a base64String into a IFormFile throws SystemInvalidOperation exception in C#
I'm trying to convert a list of base64String into a list of IFormFile. When I try MemoryStream stream = new MemoryStream(bytes) I got a stream.ReadTimeout SystemInvalidOperation. So Why it isn't working?
Here is my code:
private async…

matheusmosca
- 73
- 1
- 7
5
votes
1 answer
Attach IFormFile to mail without saving the file
Is it possible to add IFormFile files to email attachments in .net core? I am getting files from angular using formdata.
for (let file of this.files) {
this.formData.append("Files", file.nativeFile);
}
MailMessage mail = new MailMessage();
…

Nakres
- 1,212
- 11
- 27
4
votes
1 answer
How to process an iFormFile with ClosedXML with c#
I want to load an excel file into XLWorkbook
using var workbook = new XLWorkbook("iFormFile needs to go here");
var ws = workbook.Worksheet(1);

Ashane Alvis
- 770
- 2
- 18
- 42
4
votes
1 answer
Create FormFile from Stream
I want to create a FormFile in my seed function. But I get a null reference exception. Here my code
FileStream fs = new FileStream("testfile.jpg", FileMode.Open, FileAccess.Read);
FormFile file = new FormFile(fs, 1024, fs.Length, "testfile",…

Sardoan
- 767
- 1
- 10
- 25
4
votes
1 answer
Should I use IFormFile to Upload Files in ASP.NET Core API
I can understand using IFormFile to upload files in an MVC web app but what is the correct method of uploading files using ASP.NET Core when writing an API supporting Swagger?
With IFormFile
[HttpPost("{id}/content", Name…

Muhammad Rehan Saeed
- 35,627
- 39
- 202
- 311