0
我試圖從多部分構成讀上傳的文件:不能在HTTP頭文件名查找
<form action="http://localhost:17034/api/v1/reports/create" method="post" enctype="multipart/form-data">
<input type="text" name="myFile" id="myFile" /><br />
<input type="text" name="Description" id="Description" /><br />
<input type="file" name="Content" id="content" />
<input type="submit" value="Submit" />
</form>
我控制器操作是這樣的:
[HttpPost]
[Route("reports/create")]
public async Task<HttpResponseMessage> Create()
{
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (HttpContent ctnt in provider.Contents)
{
//I want to ensure I read text files as a stream so want
//to check the file extension
var fileName = ctnt.Headers.ContentDisposition.FileName //NULL FOR FILE INPUT
}
如果我檢查內容部署時,我提出我的表格文件輸入,我得到這個:
{form-data; name="myFile"}
CreationDate: null
DispositionType: "form-data"
FileName: null
FileNameStar: null
ModificationDate: null
Name: "\"myFile\""
Parameters: Count = 1
ReadDate: null
Size: null
dispositionType: "form-data"
parameters: Count = 1