I have the following simple method that creates a simple FormFile for testing.
private static IFormFile CreateTemporaryFile(string fileName, string contentType)
{
byte[] bytes = Encoding.UTF8.GetBytes("Test content");
var formFile = new FormFile(
baseStream: new MemoryStream(bytes),
baseStreamOffset: 0,
length: bytes.Length,
name: "Data",
fileName: fileName);
formFile.ContentType = contentType;
return formFile;
}
It keeps throws a NullReference exception at this line formFile.ContentType = contentType;.
We have instance of the FormFile and ContentType is a public string property with getter and setter ? Am I missing anything ?
