我有问题阅读,把XML文件上载到扼杀,而不是档案。
我的问题是,当我试图进入溪流时(var stream = 部分.ContentReadStream
),那就关闭了。 我感到,它正在查阅封闭档案。 Am I 采用多端表格,不正确? 档案尺寸只有很少几公斤,因此不应成为问题。
[WebInvoke(Method = "POST", UriTemplate = "{importFile}")]
public HttpResponseMessage Upload(string importFile, HttpRequestMessage request)
{
if (!request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
// Create a stream provider for setting up output streams
MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider();
// Read the MIME multipart content using the stream provider we just created.
var task = request.Content.ReadAsMultipartAsync(streamProvider);
task.Wait();
IEnumerable<HttpContent> bodyparts = task.Result;
string submitter;
if (!bodyparts.TryGetFormFieldValue("submitter", out submitter))
{
submitter = "unknown";
}
// Get list of local file names from stream provider
IDictionary<string, string> bodyPartFileNames = streamProvider.BodyPartFileNames;
var parser = this.parserFactoryFactory.CreateParser();
foreach (var part in bodyparts)
{
using (var stream = part.ContentReadStream)
{
using (var streamReader = new StreamReader(stream))
{
string content = streamReader.ReadToEnd();
var results = parser.Parse(content);
}
}
}
return new HttpResponseMessage(HttpStatusCode.Accepted);
}
This is my post
<h3>Data import test</h3>
<form action="/api/data/Upload" enctype="multipart/form-data" method="POST">
<input type="file" name="importFile"/>
<input type="submit" value="Upload"/>
</form>